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

Unassigned Reference Exception although it is assigned

$
0
0
I'm having issues with assigning a GameObject to my script. I've tried assigning it through the inspector and defining it in code, but neither worked. I started to get the error when I introduced touch inputs into the game. But I can't seem to fix it now. Any help would be much appreciated! ![alt text][1] ![alt text][2] public class HeartTap : MonoBehaviour { public GameObject heart; public Vector2 touchPosition, heartPosition; void Start() { } void Update() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); touchPosition = new Vector2(Camera.main.ScreenToWorldPoint(touch.position).x, Camera.main.ScreenToWorldPoint(touch.position).y); heartPosition = new Vector2(heart.transform.position.x, heart.transform.position.y); print("X Touch: " + touchPosition.x + " Y Touch: " + touchPosition.y); print("X Heart: " + heartPosition.x + " Y Heart: " + heartPosition.y); if (touchPosition == heartPosition) { print("Good"); } } } [1]: /storage/temp/149110-screen-shot-2019-11-23-at-115648-am.png [2]: /storage/temp/149111-screen-shot-2019-11-23-at-115818-am.png

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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