1
votes

My enemy script is linked to a prefab and being instantiated by my main script.

It kills enemies in a random order (I am jumping on them and some are not dying, not what I want). (what I am trying to achieve is an enemy to die when I jump on its head and play a death animation. So from this enemy script I call the other script jump <-- which is linked to my player script and get the jump Boolean value. Could the processing of jump be to slow? I need help I tried everything) it works but only on certain enemies any ideas why? Thanks community.

Can anyone help me find a better method?

Could someone help me maybe find if the Players y => an amount to change jump var on the enemy

Just had a perfect run, whats wrong with this its working then not then it is partly working

If I add audio, it doesn't work.

#pragma strict
var enemy : GameObject;
var speed : float = 1.0;
var enemanim : Animator;
var isdying : boolean = false;
private var other : main;
var playerhit: boolean = false;


function Start () {
    other = GameObject.FindWithTag("Player").GetComponent("main");
    this.transform.position.x = 8.325;
    this.transform.position.y = -1.3;
    enemanim = GetComponent(Animator);
    enemanim.SetFloat("isdead",0);
}

function OnCollisionEnter2D(coll: Collision2D) {
    if(coll.gameObject.CompareTag("distroy")){
        Destroy(enemy.gameObject);
    }
    if(coll.gameObject.CompareTag("Player")){
        playerhit=true;
    }
}
function Update () {
    if(other.jumped === true && playerhit==true){ *****the jumped i need
        enemanim.SetFloat("isdead",1);
    }
}
function FixedUpdate(){
    this.transform.Translate(Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0, 0));
    this.rigidbody2D.velocity = Vector2(-5,0);
}
1
please open your questions with a summary of the problem rather than a block of code. You'll find more tips on how to write better questions in the help center, which will improve your chances of getting (good) answers.LearnCocos2D

1 Answers

1
votes
if(other.jumped === true && playerhit==true)

Is wrong.

It should be:

if(other.jumped == true && playerhit==true)

All 3 languages used by Unity, C#, UnityScript, and Boo, are compiled into the same IL byte code at the end. However, there are cases where UnityScript has some overhead as Unity does things in the background. One of these is that it does wrapping of access to members of built-in struct-properties like transform.position.

I prefer C#, I think it is better.