📜  如何让一个 2D 对象在统一 2D 中跟随另一个 2D 对象 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:10.410000             🧑  作者: Mango

代码示例1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FishFollow : MonoBehaviour
{
    public float Speed =;

    private Transform target;


    void Start() 
    {
        target = GameObject.FindGameObjectWithTag("Player").GetCOmponent();
    }

    void Update()
    {

        transform.position = Vector2.MoveTowards(transform.position, target.position, Speed * Time.deltaTime);
    }
}