Created
March 1, 2018 03:59
-
-
Save tsubaki/d952c6e592e78118bd884adfdf152d93 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 interface IMove | |
{ | |
void SetTarget(Transform newtarget); | |
} |
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 MoveTo : MonoBehaviour ,IMove | |
{ | |
Transform target; | |
public void SetTarget(Transform newTarget) | |
{ | |
target = newTarget; | |
} | |
void Update () | |
{ | |
transform.position += Vector3.ClampMagnitude( target.position - transform.position, 0.3f); | |
} | |
} | |
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 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