I am creating a channels-based control system for doors (don’t worry if you don’t understand that bit) and I have just got the script to move the attached object using:
this.gameObject.transform.position += Movement;
This, as expected, jumps to that position (or rather adds it on) but it is instantaneous, I am wondering if there is any way to do this with a smoother transition, like seeing it move, I don’t want to animate it as I want it to be quite quick to use and implement and will be using it in a lot of places.
I’m not the best with enums really but try declaring the Method MovementMethod outside of the start function with your other variables to make it global.
Then you need to say which type you want to check for, from which enum. (You could have many different enums in one script possibly with the same MoveTowards parameter. So you would use Method.MoveTowards
That would look like this:
(It also gives you a handy little drop down box in your inspector)
public enum Method { MoveTowards, Lerp };
public Method MovementMethod;
void Update()
{
if (MovementMethod == Method.MoveTowards)
{
}
}
Managed to fix this in one area but broke another.
My way of looking for the objects giving off the correct channel used arrays has stopped working and I can now lo longer start without getting an “Array out of range” error.
using UnityEngine;
using System.Collections;
public class GateScript : MonoBehaviour
{
public bool IsActive = true;
public Vector3 Movement;
public int BroadcastChannel;
public enum Method { MoveTowards, Lerp };
public Method MovementMethod = Method.MoveTowards;
private GateControl[] ControlsPanels;
void Start()
{
GateControl[] ControlsPanels = FindObjectsOfType(typeof(GateControl)) as GateControl[];
}
void Update()
{
foreach (GateControl ControlPanel in ControlsPanels)
{
if (ControlPanel.BroadcastChannel == BroadcastChannel && ControlPanel.SignalSent)
{
this.gameObject.transform.position += Movement;
if (MovementMethod == Method.MoveTowards)
{
this.gameObject.transform.position = Vector3.MoveTowards(this.gameObject.transform.position, Movement, Time.deltaTime);
}
if (MovementMethod == Method.Lerp)
{
this.gameObject.transform.position = Vector3.Lerp(this.gameObject.transform.position, Movement, Time.deltaTime);
}
}
}
}
}