“unidade siga objeto” Respostas de código

C# unidade siga objeto

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;
        }
    }
}
Hello There

Como fazer um GameObject seguir o caminho de outro objeto

void Update()
{
transform. position = Vector3. Lerp(transform. position, target. position, speedPosition * Time. deltaTime);
transform. rotation = Quaternion. Slerp(transform. rotation, target. rotation, speedRotation * Time. deltaTime);
}
Brainy Boar

unidade siga objeto

public class FollowObject : MonoBehaviour
{

    public GameObject objectToFollow;

    public float speed = 2.0f;

    void Update()
    {
        float interpolation = speed * Time.deltaTime;

        Vector3 position = this.transform.position;
        position.y = Mathf.Lerp(this.transform.position.y, objectToFollow.transform.position.y, interpolation);
        position.x = Mathf.Lerp(this.transform.position.x, objectToFollow.transform.position.x, interpolation);
        position.z = Mathf.Lerp(this.transform.position.z, objectToFollow.transform.position.z, interpolation);

        this.transform.position = position;
    }
}
AULOX

Respostas semelhantes a “unidade siga objeto”

Perguntas semelhantes a “unidade siga objeto”

Mais respostas relacionadas para “unidade siga objeto” em C#

Procure respostas de código populares por idioma

Procurar outros idiomas de código