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 :: materials pink in unity 
Csharp :: remove first object from list c# 
Csharp :: how to unfreeze a rotation in a collider unity 2d 
Csharp :: Codewars Multiply 
Csharp :: blank background for button wpf 
Csharp :: c# how to open file explorer 
Csharp :: c# file exist 
Csharp :: unity detect object with raycast 
Csharp :: gvrviewer.instance.triggered replacement unity 
Csharp :: mvc input type file 
Csharp :: C# delete last enviroment new line 
Csharp :: elevated priviledge in c# 
Csharp :: unity put children in list 
Csharp :: c# list get element from end 
Csharp :: unity change color of sprite in script 
Csharp :: c# datetimepicker set weeks before today 
Csharp :: convert int to uint c# 
Csharp :: c# keep console open 
Csharp :: unique id c# 
Csharp :: http error 502.5 asp.net core 2.2 
Csharp :: Xamarin.Forms - How to navigate to a tabbed page child page 
Csharp :: how to change textMesh Pro unity 
Csharp :: how to cjeck if a string has a word c# 
Csharp :: unity rotate towards 
Csharp :: c# append textbox 
Csharp :: generate random name c# 
Csharp :: replace double backslash with single backslash c# 
Csharp :: Unity disable turn off component 
Csharp :: c# mailmessage set sender name 
Csharp :: .net Core Get File Request 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =