Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MoveThis : MonoBehaviour {
- public bool isSelected = false;
- GameObject platform;
- int targetpos;
- float speed = 5f;
- int origPos;
- int ctr;
- bool move = false;
- bool cancel = false;
- bool here = false;
- Vector3 origin;
- Vector3 platformPosition;
- Vector3 moveTarget;
- // Use this for initialization
- void Start () {
- //save start and platform location xdddd
- origin = transform.position;
- platformPosition = GameObject.Find("Platform").transform.position;
- Debug.Log ("Start");
- platform = GameObject.Find ("Platform");
- /*transform.position = Vector3.MoveTowards (transform.position, GameObject.Find ("Platform").transform.position,2.f);
- Quaternion targetRot = Quaternion.LookRotation (targetpos - origPos);
- transform.rotation = Quaternion.Slerp (origPos, targetpos, .2f);*/
- }
- // Update is called once per frame
- void Update () {
- if (move && moveTarget != null) {
- // transform.rotation = Quaternion.Slerp (origPos, targetpos, .2f);
- transform.position = Vector3.MoveTowards (transform.position, moveTarget, speed * Time.deltaTime);
- }
- if (transform.position == moveTarget) {
- move = false;
- moveTarget = null;
- }
- }
- void OnMouseDown()
- {
- //we dont need to move the currently selected player, you can add additional logic here for the current player to go back when clicked
- if (isSelected) {
- //test?
- //uncomment below, see what happens
- //BackToOrigin();
- return;
- }
- GameObject[] players = GameObject.FindObjectsWithTag("Player");
- foreach(GameObject p in players) {
- MoveThis mv = p.GetComponent<MoveThis>();
- //move the current selected back to its origin
- if (mv.isSelected) {
- mv.BackToOrigin();
- }
- }
- isSelected = true;
- MoveToPlatform();
- }
- public void MoveToPlatform() {
- if (!move && isSelected) {
- moveTarget = platformPosition;
- move = true;
- }
- }
- public void BackToOrigin() {
- if (!move) {
- moveTarget = origin;
- move = true;
- isSelected = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement