Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Move : MonoBehaviour
- { [SerializeField]
- private GameObject target;
- [SerializeField]
- private GameObject target2;
- [SerializeField]
- private bool weOnAPoint;
- // Update is called once per frame
- void Update()
- {
- transform.position = Vector3.MoveTowards(transform.position, weOnAPoint ? target2.transform.position : target.transform.position, .2f);
- }
- void OnTriggerEnter2D(Collider2D col)
- {
- if (col.gameObject.name == "A") weOnAPoint = true;
- if (col.gameObject.name == "B") weOnAPoint = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment