Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created March 1, 2018 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/d952c6e592e78118bd884adfdf152d93 to your computer and use it in GitHub Desktop.
Save tsubaki/d952c6e592e78118bd884adfdf152d93 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public interface IMove
{
void SetTarget(Transform newtarget);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveTo : MonoBehaviour ,IMove
{
Transform target;
public void SetTarget(Transform newTarget)
{
target = newTarget;
}
void Update ()
{
transform.position += Vector3.ClampMagnitude( target.position - transform.position, 0.3f);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawn : MonoBehaviour
{
[SerializeField] GameObject prefab;
[SerializeField] Transform target;
void Start()
{
var obj = GameObject.Instantiate(prefab);
obj.GetComponent<IMove>().SetTarget(target);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment