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

Null Reference Exception Error

$
0
0
Hello, I keep getting this error in my 2D C# game: NullReferenceException: Object reference not set to an instance of an object Character.ThrowKnife (Int32 value) (at Assets/Scripts/Character.cs:43) Player.ThrowKnife (Int32 value) (at Assets/Scripts/Player.cs:171) here is the Character code: public virtual void ThrowKnife(int value) { if (facingRight) { GameObject tmp = (GameObject)Instantiate(knifePrefab, KnifePos.position, Quaternion.Euler(new Vector3(0, 0, -90))); tmp.GetComponent().Initialize(Vector2.right); } else { GameObject tmp = (GameObject)Instantiate(knifePrefab, KnifePos.position, Quaternion.Euler(new Vector3(0, 0, 90))); tmp.GetComponent().Initialize(Vector2.left); } } and here is the Player code: public override void ThrowKnife(int value) { if (!OnGround && value == 1 || OnGround && value == 0) { base.ThrowKnife(value); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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