VitalyD

Untitled

Mar 7th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Move : MonoBehaviour
  6. {   [SerializeField]
  7.     private GameObject target;
  8.     [SerializeField]
  9.     private GameObject target2;
  10.     [SerializeField]
  11.     private bool weOnAPoint;
  12.    
  13.     // Update is called once per frame
  14.     void Update()
  15.     {
  16.         transform.position = Vector3.MoveTowards(transform.position, weOnAPoint ? target2.transform.position : target.transform.position, .2f);
  17.     }
  18.  
  19.     void OnTriggerEnter2D(Collider2D col)
  20.     {
  21.         if (col.gameObject.name == "A") weOnAPoint = true;
  22.         if (col.gameObject.name == "B") weOnAPoint = false;
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment