Hello guys !
Am pretty new to unity programming and got stuck lately by an annoying bug. Searched a lot on the internet but maybe I am too stupid to understand what I am doing wrong or maybe it’s just not in there. (Pity, help me)
So here is the things. I am using a UFPS camera to travel in my scene and a second camera, not moving at all, to display a clickable UI.
So i put a script on a wall for instance, when the guy click on the wall, it switches camera and show him some buttons to change the wall textures.
My bug is that, when I click on the wall it says me this :
NullReferenceException: Object reference not set to an instance of an object
Canvas_Activer.Start () (at Assets/Scripts/Canvas_Activer.cs:24)
(canvas activer being my script)
using UnityEngine;
using System.Collections;
public class Canvas_Activer : MonoBehaviour {
public string CanvasName;
public int Timer;
public float Speed=1.0f;
private GameObject Canvas;
private Canvas CanvasComponent;
private GameObject Maincamera;
private Camera MovingCamera;
private float timing=0.0f;
private bool flag=false;
private float startTimer;
// Use this for initialization
void Start () {
GameObject Canvas = GameObject.Find(CanvasName);
GameObject Maincamera = GameObject.Find("FPSCamera");
CanvasComponent = Canvas.GetComponent<Canvas>();
MovingCamera = Maincamera.GetComponent<Camera>() as Camera;
}
void Update () {
if(flag == true){
timing = Time.time - startTimer;
Screen.showCursor = true;
Debug.Log(timing);
Maincamera.camera.enabled=false;
if(timing>Timer){
CanvasComponent.enabled=false;
Screen.showCursor = false;
flag = false;
}
}
}
void OnMouseOver(){
Screen.showCursor = true;
if(Input.GetButton("Fire1")){
CanvasComponent.enabled=true;
startTimer = Time.time;
flag = true;
}
}
}
Tryed out a lot of things but… just can’t do it
If someone could help me, I would really be gratefull
Thanks all !