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 :: how to assign 2d physics material through script 
Csharp :: visual studio 2019 problem create new .net framework class library 
Csharp :: how to do division with button C# 
Csharp :: c# datagridview select row index programmatically 
Csharp :: how to combine constructors in c# 
Csharp :: entity framework dynamic search solution 1 
Csharp :: c# .net RemoveClaim auth 
Csharp :: Bitwise Left Shift C# 
Csharp :: F# convert generic.List to list 
Csharp :: ef core index attribute 
Csharp :: [range(typeof(bool),"true","true", 
Csharp :: Query Parent-GrandChild collection 
Csharp :: c# Showing a hidden WPF window 
Csharp :: you have the following c# code. sb is a a very long string. you need to identify whether a string stored in an object named stringtofind is within the stringbuilder sb object. which code should you use? 
Csharp :: list to array f# 
Csharp :: finding holydays asp.net 
Csharp :: read text c# 
Csharp :: virtual list entity framework 
Csharp :: How to set a Printer Port in C# on a specified Printer 
Csharp :: open html file in browser using c++ 
Csharp :: two lowest positive numbers given an array of minimum 
Csharp :: c# rotate sum array 
Csharp :: how to do if statement based on date in asp net c# 
Csharp :: convert console app to linux 
Csharp :: c# deeply related children 
Csharp :: unity play audio from particle system 
Csharp :: set field in list linq 
Csharp :: google script get font color 
Csharp :: C# pull appart property chain in expression 
Csharp :: DrawImage resize to target size c# 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =