Skip to content

Instantly share code, notes, and snippets.

@modyari
Created January 2, 2022 18:48
Show Gist options
  • Select an option

  • Save modyari/1e8ad4576b223c566b40122a73a1bc34 to your computer and use it in GitHub Desktop.

Select an option

Save modyari/1e8ad4576b223c566b40122a73a1bc34 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class MoveToPlayer : MonoBehaviour
{
public Transform player;
public float speed;
public float maxDistance;
void Update()
{
if (Vector3.Distance(player.position, transform.position) < maxDistance)
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, player.position, step);
}
}
}
@modyari
Copy link
Copy Markdown
Author

modyari commented Jan 2, 2022

Bad example of how to structure unity behaviours

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment