- Home /
Question by
Nightmares_Dawn · Aug 08, 2015 at 01:00 PM ·
unity 5javascriptraycast
Raycast Pause Between Hits?
When the Mouse Button is spammed the raycast hits multiple times instead of waiting till the animation is done any ideas??
#pragma strict
var TheDamage = 200;
var Effect : Transform;
function Update () {
Hit();
}
function Hit() {
if (Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var pos = Vector3(Screen.width / 2, Screen.height / 2, Camera.main.nearClipPlane);
var ray = Camera.main.ScreenPointToRay(pos);
animation.Play("Axe");
if (Physics.Raycast(ray, hit, 5))
{
yield WaitForSeconds(0.4);
var particalClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(Vector3.up, hit.normal));
Destroy (particalClone.gameObject, 0.5);
hit.transform.SendMessage("ApplyDammage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
yield WaitForSeconds(3);
}
Comment
First of all, you're running WaitForSeconds in Update which is not how it works.
I recommend using Time to do a rough time increment with a boolean preventing the player to fire multiple times at once.
Your answer
Follow this Question
Related Questions
Why UI layer is being ignored by the raycast? 0 Answers
Switch GameObjects Tags with javascript 1 Answer
RaycastHit2D.collider is null - why? 1 Answer
Raycasting fail 1 Answer