61
Support / Re: delegate
« on: June 25, 2012, 10:47:55 am »
wow,
so you have 2 objects "animation" & "animatedSprite" ? how do you declare them ?
by the way, there is my code with the added line from yours (
so you have 2 objects "animation" & "animatedSprite" ? how do you declare them ?
by the way, there is my code with the added line from yours (
Code: [Select]
if (animation.IsPlaying()...
) but no animation fires... :Code: [Select]
void Start ()
{
anim = GetComponent<tk2dAnimatedSprite> ();
}
void Update ()
{
if (Input.GetKeyDown ("space")) { // jump
rigidbody.AddRelativeForce (transform.up * jumpSpeed, ForceMode.Impulse);
}
// if not hiding
if (!hiding) {
movement = Input.GetAxis ("Horizontal") * moveSpeed;
movement *= Time.deltaTime;
transform.Translate (movement, 0.0f, 0.0f);
if (Input.GetKeyDown (KeyCode.S)) { // hide
anim.Play ("hide");
hiding = true;
} else if (Input.GetKeyDown (KeyCode.D)) { // walk right
if (anim.isPlaying () && anim.CurrentClip.name != "walkleft")
anim.Play ("walk");
if (!goingRight)
anim.FlipX ();
goingRight = true;
} else if (Input.GetKeyDown (KeyCode.A)) { // walk left
if (anim.isPlaying () && anim.CurrentClip.name == "walkleft")
anim.Play ("walk");
if (goingRight)
anim.FlipX ();
goingRight = false;
} else {
anim.Play ("idle");
}
} else {
// unhide
if (Input.GetKeyDown (KeyCode.W)) {
anim.Play ("unhide");
hiding = false;
}
}
}