This code is meant to make the object follow the main camera in the scene, but now I can’t move the camera.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pickup_cube : MonoBehaviour {
public bool holding;
void OnMouseDown()
{
holding = true;
}
void OnMouseUp()
{
holding = false;
}
void Update()
{
if(holding == true)
{
this.transform.SetParent(Camera.main.transform);
}
if(holding == false)
{
this.transform.SetParent(Camera.main.transform);
}
}
}
johne5
March 4, 2017, 1:24am
2
So you’re setting this gameobject to be a child of the camera. and when the camera is moving the child will fallow.
You must have another script that is controlling the movement. You might need to show us the movement script.
Is this script working. setting this object as a child?
milo55545:
This code is meant to make the object follow the main camera in the scene, but now I can’t move the camera.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pickup_cube : MonoBehaviour {
public bool holding;
void OnMouseDown()
{
holding = true;
}
void OnMouseUp()
{
holding = false;
}
void Update()
{
if(holding == true)
{
this.transform.SetParent(Camera.main.transform);
}
if(holding == false)
{
this.transform.SetParent(Camera.main.transform);
}
}
}
i do not know if this is your main issue but , you are setting the parent transform every frame on update .
both your evaluations branch out towards the same piece of code …