Question by
$$anonymous$$ · Nov 14, 2016 at 02:24 PM ·
raycastfpsbullethole
NullReferenceException: Object reference not set to an instance of an object BulletScript.Update () (at Assets/Scripts/BulletScript.js:8)
Hello :D
I'm a beginner in Unity so I need some help
I'm trying to make a first person shooter for a school project. I was trying to add in bullet holes and then I've encountered this problem and I have no idea on how to solve it...
I was hoping if you guys are able to help me.
NullReferenceException: Object reference not set to an instance of an object BulletScript.Update () (at Assets/Scripts/BulletScript.js:8)
Here is the script:
var maxDist : float = 1000000000;
var decalHitWall : GameObject;
var floatInFrontOfWall : float = 0.00001;
function Update ()
{
var hit : RaycastHit;
if (Physics.Raycast(transform.position, transform.foward, hit, maxDist))
{
if (decalHitWall && hit.transform.tag == "Level Parts")
Instantiate(decalHitWall, hit.point + (hit.normal * floatInFrontOfWall), Quaternion.LookRotation(hit.normal));
}
}
Thank you in advance :D
Comment
I think you haven't assigned the decalHitWall
in your script. Either assign the object in the inspector or load from resources folder. Example
Your answer
Follow this Question
Related Questions
Disable Damage Raycast? 1 Answer
Raycast Weapon not cause damage 1 Answer
Raycast to multiple objects 2 Answers