Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity camera follow

	// Script Shoud be placed on Camera.
	[SerializeField] private Transform target; // Target
	[SerializeField] private Vector3 offset; // Vector3 offset
	[SerializeField] [Range(0, 1)] private float smooth= 0.125f; // Smoothing
    [SerializeField] [Range(0, 10)] private float Speed = 10f; // Follow Speed

    private void FixedUpdate()
	{
		Vector3 vector = this.target.position + this.offset;
		Vector3 position = Vector3.Lerp(base.transform.position, vector, (this.smooth + this.Speed)* Time.deltaTime);
		base.transform.position = position;
	}
Comment

unity camera follow

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 :: c# thread wait 
Csharp :: generate a random number in c# 
Csharp :: double tryparse dot comma 
Csharp :: c # c^b 
Csharp :: c# unity 2d play video 
Csharp :: how to generate random letters in C# 
Csharp :: base64 string to byte array c# 
Csharp :: get web config key value in c# razor view 
Csharp :: iterate through xpdictionary devexpress 
Csharp :: unity detect if animation is playing 
Csharp :: set label position winforms 
Csharp :: C# .net core convert int to enum 
Csharp :: how to parse a string to an integer c# 
Csharp :: c# read from text documenmt 
Csharp :: time.timescale 
Csharp :: C# int.parse input string wasnt in correct format 
Csharp :: loop over all values in enum 
Csharp :: c# convert string to enum value 
Csharp :: c# reading months as int 
Csharp :: bubble sort in c# 
Csharp :: change vignette intensity unity 
Csharp :: c# dictionary first 
Csharp :: how to play animation with code in unity 
Csharp :: c# how to terminate console application 
Csharp :: how to make a enum list in c# 
Csharp :: make invisible unity 
Csharp :: hide datagrid column c# 
Csharp :: csproj include folder and files 
Csharp :: convert generic to type c# 
Csharp :: .net Core Return File like File Server 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =