Tuesday, February 9, 2016

c# - How do I have a camera follow my object in Unity?


I have an object that automatically moves by itself and I want the main camera to automatically follow it.(Like in games such as geometry dash and jetpack joyride) This is the code for the automatic moving object in case it is needed:


using UnityEngine;
using System.Collections;
public class automove : MonoBehaviour {
public static int movespeed = 5;
public Vector3 userDirection = Vector3.right;




public void Update()
{
transform.Translate(userDirection * movespeed * Time.deltaTime);
}
}

So does anyone know any good scripts I could add to the main camera to follow this object that automatically moves? Thanks in advance!




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...