Toogle Parent to Camera Function - Google Cardboard
Hi, I'm trying to test the google cardboard SDK. I wanted to create a Cube that on click (tap-magnetic trigger) parents itself to the 'Main Camera' (Camera Object name) and on the second click unparents itself. I'm tried to create a function called 'ToogleParent' to attach it to the event trigger 'Pointer Click' of the cube. But sadly it doesn't work. I'm very new to Unity and C# and can't get it to work.
This is the code I used in the Cube's Script:
public void ToggleParent() {
if (transform.parent = null) {
transform.parent = GameObject.Find("Main Camera").transform.parent;
}
else if (transform.parent != null){
transform.parent = null;
}
}
I'm very sure this is wrong but I'm trying to find out how to reference the Main Camera. Is there a better way to do this.
Thanks :)
Your answer
Follow this Question
Related Questions
How to make an object parent to a Camera through code? 0 Answers
Search for Object with largest y-Coordinates 1 Answer
How can I make a third person camera collision script? 2 Answers
How to negate shaking of moving object? 1 Answer
Roll a ball, treating where the camera is rotating as forward? 0 Answers