Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Varied footsteps - Object reference not set to an instance of an object?

$
0
0
Hello! My aim is to have different footstep sounds depending on the ground the player is walking on. The over all structure is this: variable to determine if the player is walking, raycast down if player is walking to determine what ground he/she is on, play an audio clip depending on the tag. I have this script so far, but I get the error "Object reference not set to an instance of an object?".. What is the problem here? I am not very experienced with raycasting unfortunately, haha. var snow : AudioClip; var metal : AudioClip; var walking : boolean; var hit : RaycastHit; var rayHit : boolean; function Update() { var dwn = transform.TransformDirection (-Vector3.up); if(Input.GetKeyDown("w") || Input.GetKeyDown("a") || Input.GetKeyDown("s") || Input.GetKeyDown("d")) { walking = true; } else if (Input.GetKeyUp("w") || Input.GetKeyUp("a") || Input.GetKeyUp("s") || Input.GetKeyUp("d")) { walking = false; } if (walking&&Physics.Raycast (transform.position, dwn)&&hit.transform.gameObject.tag == "metalfloor") { audio.clip = metal; audio.Play(); } if (walking&&Physics.Raycast (transform.position, dwn)&&hit.transform.gameObject.tag == "snowfloor") { audio.clip = snow; audio.Play(); } } Thanks for your time, you guys are great with questions :)

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>