- Home /
Transform not changing to correct target transform
Hi! I seem to have a problem with my code, and its probably something silly I'm overlooking. What im doing is making a google cardboard simulation where there are orbs around the environment, if you press on one it runs the MoveTo() function with the input being the transform of itself, which I then set my orbPoint to, which if the bool orbs is enabled my camera should Lerp to that position, However when I input any position into my MoveTo() function, it always returns the last transform of my list of orbs. Here's my code, I hope somebody can shed some light on the subject, and hopefully it's not too silly.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraRig : MonoBehaviour
{
public Transform[] point;
public Transform startPoint;
public int nextPoint = 0;
public float speed = 1;
public bool finished = false;
public bool moving = true;
public float delay = 3f;
private float dist;
public bool orbs;
public Transform orbPoint;
public void Start()
{
if (speed <= 0)
{
speed = 0.03f;
}
orbPoint = point[0];
nextPoint = 0;
finished = false;
moving = true;
transform.position = startPoint.position;
}
public void Update()
{
delay = point[nextPoint].GetComponent<Point>().delayAtThisPoint;
dist = Vector3.Distance(transform.position, point[nextPoint].position);
if (!orbs)
{
if (finished)
{
// Exit the VR tour, it's finished...
moving = false;
Debug.Log("Finished Tour");
}
if (moving)
{
transform.position = Vector3.Lerp(transform.position, point[nextPoint].position, speed * Time.deltaTime);
}
else if (!moving)
{
// We are paused.
}
if (transform.position == point[nextPoint].position || dist < 0.1)
{
if (nextPoint < point.Length - 1)
{
nextPoint++;
StartCoroutine("stopAndLook");
}
else
{
finished = true;
}
}
}
else if (orbs)
{
transform.position = Vector3.Lerp(transform.position, orbPoint.position, speed * Time.deltaTime);
}
}
IEnumerator stopAndLook()
{
moving = false;
yield return new WaitForSeconds(delay);
moving = true;
}
public void MoveTo(Transform _pos)
{
orbPoint.position = _pos.position;
Debug.Log(_pos.position + "");
}
}
Your answer
Follow this Question
Related Questions
Auto leveling help 0 Answers
problem moving a prefab object in script (c#) 0 Answers
Calling GameObject's transform from list 1 Answer
destroying game object in a specific transform 2 Answers
how are Mathf.SmoothDamp and Mathf.SmoothStep different 1 Answer