- Home /
Need help with simple RayCast Attack script
Need help writing the following script. I have an enemy that will attack a first person controller when close enough. I need the enemy to use a raycast going forward when the attack animation is playing. If the attack animation has played for a certain amount of time, use the raycast forward, and if it hits the first person controller, then take off some damage of the first person controller. The raycast will have to be a certain length of course since it is only meant to hit the frist person controller if he is close enough. Any help towards this will be appreciated! Only been programming in Unity for 8 weeks now.
Answer by zillion · Jul 11, 2012 at 08:26 AM
Currently have the following code in a Shoot function on my AI. Getting an error saying "Expressions in statements must only be executed for their side-effects" This is on the 'Health - 10;' line for some reason...
var hit : RaycastHit;
var fwd = transform.TransformDirection (Vector3.forward); if (Physics.Raycast (transform.position, fwd, 10)) { if(hit.collider.gameObject.tag == "Player") { Health - 10; } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613074020im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Restricting camera movement in first person camera? 0 Answers
Take damage after seconds 3 Answers
Need coding help with fps 0 Answers
Question about FPS and Raycasting Javascript 2 Answers
Minecraft-like arms 1 Answer