Cant get setParent to actually set the parent for child.
I have a camera with a script that makes the camera look at whatever its parent object is:
public class LookAt : MonoBehaviour
{
public Camera cam;
void Update()
{
cam.transform.LookAt(transform.parent);
}
}
I am trying to use setParent with worldPositionStays as false so that the camera stays relative to the new parent as it was to the old parent.
public class ParentSwitch : MonoBehaviour
{
public Camera child;
public Transform currentParent;
public Transform newParent;
void start()
{
child.transform.SetParent(currentParent);
}
void update ()
{
if (Input.GetKeyDown("space")) {
child.transform.SetParent(newParent, false);
}
}
}
The script doesn't throw up any errors but also change the parent either, I've been looking at the SetParent documentation and looking up SetParent examples online and cant figure how why its not working. I have also tried having
public GameObject child;
Instead of
public Camera child;
and the result was no different, nothing happens.
Thanks in advance for any help! :)
Your answer
Follow this Question
Related Questions
UnityException: Transform child out of bounds (C# Unity) 0 Answers
Deleting objects at specific position 1 Answer
Help Moving GameObject of a Type 0 Answers
Operator '==' is ambiguous on operands of type 'Vector2' and 'Vector3' 1 Answer
Position Child Object to center of Parent Object [SOLVED] 1 Answer