so i have a camera script which is passed a gameobject at creation, but when it runs it doesnt see the gameobject. I put a debug just above the line where it is using the object (Target) and this is what it gave me
the last 3 console entries scroll forever.
and the two “target according to the camera: …” lines are from the exact same line of code
the error in the middle is from the line immediately after the debug.log.
the 2 relevant code snippets are the code that creates the camera
public void BuildCamera(float AspectRatio,ref GameObject Target,float FollwSpeed)
{
var c = Instantiate(CameraPrefab) as GameObject;
c.SetActive(false);
var s = c.AddComponent<NonScaleCamera>();
s.Target = Target;
Debug.Log("Target passed is: " + Target);
Debug.Log("Target recieved is: " + s.Target);
s.baseAspect = AspectRatio;
s.FollowSpeed = FollwSpeed;
c.SetActive(true);
}
and the camera update
void Update()
{
Debug.Log("target according to camera is: " + Target);
if (Target != null)
workAroundTest = Target.transform.position;
TargetPos = Vector2.Lerp(transform.position, workAroundTest, Time.deltaTime * FollowSpeed);
}
I know that I can probably just use a different script, but this is the weirdest thing i have seen while using unity.