Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MoveThis : MonoBehaviour {
  5.  
  6. public bool isSelected = false;
  7.  
  8. GameObject platform;
  9. int targetpos;
  10. float speed = 5f;
  11. int origPos;
  12.  
  13. int ctr;
  14. bool move = false;
  15. bool cancel = false;
  16. bool here = false;
  17.  
  18. Vector3 origin;
  19. Vector3 platformPosition;
  20. Vector3 moveTarget;
  21.  
  22. // Use this for initialization
  23. void Start () {
  24. //save start and platform location xdddd
  25. origin = transform.position;
  26. platformPosition = GameObject.Find("Platform").transform.position;
  27.  
  28. Debug.Log ("Start");
  29. platform = GameObject.Find ("Platform");
  30. /*transform.position = Vector3.MoveTowards (transform.position, GameObject.Find ("Platform").transform.position,2.f);
  31. Quaternion targetRot = Quaternion.LookRotation (targetpos - origPos);
  32. transform.rotation = Quaternion.Slerp (origPos, targetpos, .2f);*/
  33. }
  34.  
  35. // Update is called once per frame
  36. void Update () {
  37. if (move && moveTarget != null) {
  38. // transform.rotation = Quaternion.Slerp (origPos, targetpos, .2f);
  39. transform.position = Vector3.MoveTowards (transform.position, moveTarget, speed * Time.deltaTime);
  40. }
  41.  
  42. if (transform.position == moveTarget) {
  43. move = false;
  44. moveTarget = null;
  45. }
  46. }
  47.  
  48. void OnMouseDown()
  49. {
  50. //we dont need to move the currently selected player, you can add additional logic here for the current player to go back when clicked
  51. if (isSelected) {
  52. //test?
  53. //uncomment below, see what happens
  54. //BackToOrigin();
  55. return;
  56. }
  57. GameObject[] players = GameObject.FindObjectsWithTag("Player");
  58. foreach(GameObject p in players) {
  59. MoveThis mv = p.GetComponent<MoveThis>();
  60. //move the current selected back to its origin
  61. if (mv.isSelected) {
  62. mv.BackToOrigin();
  63. }
  64. }
  65.  
  66. isSelected = true;
  67. MoveToPlatform();
  68. }
  69.  
  70. public void MoveToPlatform() {
  71. if (!move && isSelected) {
  72. moveTarget = platformPosition;
  73. move = true;
  74. }
  75. }
  76.  
  77. public void BackToOrigin() {
  78. if (!move) {
  79. moveTarget = origin;
  80. move = true;
  81. isSelected = false;
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement