Hi,
I have some problem getting the mouse to work, I want to click on an object to turn on/off the game. But I can’t is giving me this NullReferenceException: Object reference not set to an instance of an object. I have no idea why, this is just a test.
using UnityEngine;
using System.Collections;
public class OnOff : MonoBehaviour {
public bool on = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
RaycastHit2D hit = Physics2D.Raycast(Input.mousePosition, Vector2.zero);
if(hit != null) {
if(hit.collider.gameObject.name == "On") {
Debug.Log( "faucet");
}
}
}
}
I’m a beginner, any help? Thanks. Is c#.