Question by
matt_1 · Jul 28, 2016 at 10:28 PM ·
animationraycasttransitions
Getting the Raycast to be sent out only once in the transition between animations, not twice or three times
Hey guys, here is the script that runs the part where if im attacking, an animation plays but in the transition between idle and attack, i somehow can attack extra between the animations. but once im in the animation cycle, perfectly fine. If you need for information please ask.
bool canAttack = true;
private bool CheckCounter(){
if (anim.GetCurrentAnimatorStateInfo (0).IsName ("standing_melee_attack_downward")) {//if attacking, making attack possible = false;
print ("Attacking is playing");
return canAttack = false;
} else if(anim.GetCurrentAnimatorStateInfo (0).IsName ("HumanoidIdle")){
return canAttack = true;
}else{//if attacking is not true, and idle is not true, that means its in transition
return canAttack=false;
}
}
// Update is called once per frame
void Update () {
Ray raycast = FPSCamera.ScreenPointToRay (new Vector2 (Screen.width / 2, Screen.height / 2));
anim = GetComponent<Animator>();
RaycastHit hitInfo;
//anim.GetCurrentAnimatorStateInfo(0).IsName("standing_melee_attack_downward");
//print (canAttack);
if (Input.GetKeyDown (KeyCode.E)) {
if (CheckCounter ()) {
if (Physics.Raycast (raycast, out hitInfo, weaponRange)) {
if (hitInfo.collider.tag == "Tree") {
print ("Attacking");
treeHealth = hitInfo.collider.GetComponentInParent<TreeScript> ();
AttackTree ();
}
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Why is the reflected ray the same length as the previous and how to fix it 1 Answer
how do I use an Idle animation clip in a 2d blend tree? 0 Answers
Can't jump while running, and animation won't transition 0 Answers
Hello, help with animation between scenes 0 Answers
Track an object and fire? 0 Answers