Horje
c# unity follow object Code Example
c# unity follow object
public class Follow : MonoBehaviour
{
    public Transform Target;
    public Transform Self;
    Vector3 tempVec3 = new Vector3();

    void LateUpdate()
    {
    	// If the target is active in the scene
        if (Target != null)
        {
            tempVec3.x = Target.position.x; // Follow x position
            tempVec3.y = Target.position.y; // Follow y position
			tempVec3.z = this.transform.position.z; // For 2D
            // tempVec3.z = Target.position.y; // For 3D
          	this.transform.position = tempVec3;
        }
        // If the target is NOT active in the scene
        else if (Target == null)
        {
            tempVec3.x = Self.position.x;
            tempVec3.y = Self.transform.position.y;
            tempVec3.z = Self.transform.position.z;
            Self.transform.position = tempVec3;
        }
    }
}




Csharp

Related
base64 string to byte array c# Code Example base64 string to byte array c# Code Example
how to update a project to cross target .net core Code Example how to update a project to cross target .net core Code Example
downlaod file and use C# Code Example downlaod file and use C# Code Example
c# download file Code Example c# download file Code Example
email regex c# Code Example email regex c# Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9