Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

camera follow

public Transform player;

    public Vector3 offset;

    void LateUpdate()
    {
        transform.position = player.position + offset;
    }
Comment

camera follow player

public Transform Target; // Drag the object that will be followed in the inspector.
public Transform Camera; // Drag the camera object in the inspector.
Vector3 tempVec3 = new Vector3(); // Temporary vector 3.

void LateUpdate()
{
  	// If the target is active in the scene, set the x camera position to target.
    if (Target != null)
    {
        tempVec3.x = Target.position.x;
        tempVec3.y = this.transform.position.y;
        tempVec3.z = this.transform.position.z;
        this.transform.position = tempVec3;
    }
  	// If target is not active in the scene, set the x camera position to itself.
    else if (Target == null)
    {
        tempVec3.x = Camera.position.x;
        tempVec3.y = Camera.transform.position.y;
        tempVec3.z = Camera.transform.position.z;
        Camera.transform.position = tempVec3;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: open url in c# 
Csharp :: c# alphabet array 
Csharp :: c# exit console 
Csharp :: object spin unity 
Csharp :: how to change the color of an object in unity c# 
Csharp :: how to convert float to int in c# unity 
Csharp :: c# main file 
Csharp :: Uncaught TypeError: $(...).validate is not a function 
Csharp :: movement script c# 
Csharp :: hex string to int c# 
Csharp :: split with multiple delimiters c# 
Csharp :: stop program event in unity code 
Csharp :: unity find gameobject by name 
Csharp :: set player position unity 
Csharp :: check last character of a string c# 
Csharp :: c# create new thread 
Csharp :: unity or 
Csharp :: cannot convert string to long c# 
Csharp :: how to change particle system rate over time unity 
Csharp :: how to get all files from folder and subfolders in c# 
Csharp :: how to reference scripts in other scenes unity 
Csharp :: mouselook script unity 
Csharp :: c# press key 
Csharp :: c# require administrator permissions 
Csharp :: wpf label text color rgb string 
Csharp :: base64decode C# 
Csharp :: how to make a pause feautre in unity 
Csharp :: vuln.c nc mercury.picoctf.net 59616 
Csharp :: wpf rounded image 
Csharp :: using tmp unity 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =