Quantcast
Channel: Answers by "ransomink"
Viewing all articles
Browse latest Browse all 80

Answer by ransomink

$
0
0
using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemySkullMovement : MonoBehaviour { public float speed; private float distance; private float step; private Transform t; private Transform target; void Start() { t = transform; target = GameObject.FindGameObjectWithTag( "Player" ).transform; } void Update() { Look(); CheckDistance(); step = speed * Time.deltaTime; // Distance exist? if ( distance != 0 && distance > 1 ) { t.position = Vector3.MoveTowards( t.position, target.position, step ); } } void Look() { t.LookAt( target ); } void CheckDistance() { distance = Vector3.Distance( t.position, target.position ); Debug.Log( distance ); } }

Viewing all articles
Browse latest Browse all 80

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>