Created
November 30, 2018 12:49
-
-
Save tsubaki/f16e02a9332ce2defda8c3c7f4b8ae9c to your computer and use it in GitHub Desktop.
対象を追跡するコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class FollowTarget : MonoBehaviour | |
{ | |
[SerializeField] private Transform target; | |
void Update() | |
{ | |
var diff = target.position - transform.position; | |
transform.rotation = Quaternion.LookRotation(diff, Vector3.up); | |
transform.position += diff.normalized * Time.deltaTime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment