- Home /
Question by
SuperWyatt15 · Dec 14, 2014 at 08:54 AM ·
raycasting
I am having a problem with my RaycastShooting script.
I just recently watched one of brackeys tutorials and used his script. I get this error code only when I run the game: NullReferenceException: Object reference not set to an instance of an object RaycastShooting.Update () (at Assets/Scripts/Player/RaycastShooting.js:9).
Here is the script: #pragma strict
var Effect : Transform; var TheDammage = 100;
function Update () {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast (ray, hit, 100))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
Thank you!
Comment
Your answer