- Home /
Several animations under 1 key
Dear unity community, i've been working on a fact paced Action RPG for quiet a while now and recently stumbled upon a problem. As a rookie scripter i cant see what i've done wrong. i'm trying to make the character have an attack sequence with several animations. So press fire 1 once triggers animation 1 press it again within an X ammount of seconds will trigger animation 2 ( unless your too late ) Now with this script it wont even finish the full animation on animation 1 but neither trigger animation nr2 while it does print and show the texture.
i know it's quiet a pill but i would really appriciate the help i've tried several methods of calling up the script: animation.Blend / Animation.CrossFade etc etc here is the script i hope anyone could take the time to read through it and help me out.
var punchSpeed = 1; var punchHitTime = 0.6; var punchTime = 0.4; var punchPosition = new Vector3 (0, 0, 0.8); var punchRadius = 1.3; var punchHitPoints = 1; var combo1 = true; var combo2 = false; var combo2time:float=0.00; var combotexture: GUITexture;
private var busy = false;
function Start () { combotexture.enabled = false; }
function LateUpdate () { var controller : ThirdPersonController = GetComponent(ThirdPersonController); if(!busy && Input.GetButtonDown ("Fire1") && controller.IsGroundedWithTimeout() && !controller.IsMoving()) {
SendMessage ("DidPunch"); busy = true; } if (combo2==true&&Input.GetButtonDown ("Fire1")) { print("it works"); animation.CrossFade("P_Hit - 3", 1); //animation.Blend("P_Being hit",1); } }
function DidPunch () { if (combo1==true)animation.Play("P_Hit - 1"); yield WaitForSeconds(punchHitTime); var pos = transform.TransformPoint(punchPosition); var enemies : GameObject[] = GameObject.FindGameObjectsWithTag("Enemy");
for (var go : GameObject in enemies) {
var enemy = go.GetComponent(EnemyDamage);
if (enemy == null) continue;
if (Vector3.Distance(enemy.transform.position, pos) < punchRadius) {
enemy.SendMessage("ApplyDamage", punchHitPoints);
SendMessage("attack1");
//yield WaitForSeconds(0.5);
}
}
yield WaitForSeconds(punchTime - punchHitTime);
busy = false;
}
function attack1() { combo1 = false; combo2 = true; SendMessage ("combo2_active"); }
function combo2_active() {
combotexture.enabled = true;
yield WaitForSeconds (combo2time);
combo1 = true;
combo2 = false;
combotexture.enabled = false;
}
function OnDrawGizmosSelected () { Gizmos.color = Color.yellow; Gizmos.DrawWireSphere (transform.TransformPoint(punchPosition), punchRadius); }
Sorry for the mess it leaves :S .... tried clearing it but it just messes it up itselve again...
Your answer
Follow this Question
Related Questions
Button Opacity Animation Not Working 0 Answers
can an animation be blended between two frames? 1 Answer
Animator has not been initialized?? 3 Answers
How to change UI button animation speed (4.6 UI) 2 Answers
animate sprite in a button event 0 Answers