- Home /
Raycast with Cardboard
Helloooo
I am using the Cardboard clicker to move the Camera, Done √
But want to use the Raycast hit from the Camera to trigger smaller events.
What's wrong with the following code:
private Camera cam;
public GameObject trigger;
public bool myTrigger = false;
public GameObject myShow;
// public GameObject myHide;
// Update is called once per frame
void Update () {
if(Physics.Raycast(cam.transform.position, trigger.transform.position, Mathf.Infinity)) {
if (myTrigger == false) {
myShow.SetActive (true);
//myHide.SetActive (false);
} else {
myShow.SetActive(true);
//myHide.SetActive(true);
}
}
}
Thanks!
~be
Answer by toddisarockstar · Apr 22, 2016 at 03:36 AM
well first of all raycast is not stated in two positions. its stated as (startpoint, direction, distance).
the direction part is stated as a vector 3 direction variable you can get vector 3 direction by subtracting 2 points.
so your raycast should be stated like this:
if(Physics.Raycast(cam.transform.position,cam.transform.position-trigger.transform.position, Mathf.Infinity))
@toddisarockstar Thanks Still doesn't work. And I am getting this error
"NullReferenceException: Object reference not set to an instance of an object rayCast.Update () (at Assets/_Scripts/rayCast.cs:18)"
The script is on Camera
The trigger has a collider (set to Trigger)
Thanks!
~be