Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help me pls!!!!!

Discussion in 'iOS and tvOS' started by killerz, Jan 25, 2011.

  1. killerz

    killerz

    Joined:
    Aug 28, 2010
    Posts:
    32
    Hi all, I'm making a game like BlockOut; This is a movie from youTube : http://www.youtube.com/
    watch?v=0bg8W7J6rrY

    I've made this : http://www859.megaupload.com/files/7...e.unitypackage

    Instead of use the buttons I would like to use the touch for move the cube. If I raised the finger, I
    would that the cube move correctly in the grid (as in video).

    Could you tell me how to change the script to do this?

    Here is the code:

    Code (csharp):
    1. var hit : RaycastHit;
    2. var slotGameObject : GameObject[];
    3. var slotNumber : int = 1;
    4. var slotPosition : Vector3;
    5. var cubeY : int;
    6. var gridSize : int = 16;
    7.  
    8. function Update ()
    9. {
    10. if(slotNumber == 1)
    11. slotPosition = slotGameObject[0].transform.position;
    12. else if(slotNumber == 2)
    13. slotPosition = slotGameObject[1].transform.position;
    14. else if(slotNumber == 3)
    15. slotPosition = slotGameObject[2].transform.position;
    16. else if(slotNumber == 4)
    17. slotPosition = slotGameObject[3].transform.position;
    18. else if(slotNumber == 5)
    19. slotPosition = slotGameObject[4].transform.position;
    20. else if(slotNumber == 6)
    21. slotPosition = slotGameObject[5].transform.position;
    22. else if(slotNumber == 7)
    23. slotPosition = slotGameObject[6].transform.position;
    24. else if(slotNumber == 8)
    25. slotPosition = slotGameObject[7].transform.position;
    26. else if(slotNumber == 9)
    27. slotPosition = slotGameObject[8].transform.position;
    28. else if(slotNumber == 10)
    29. slotPosition = slotGameObject[9].transform.position;
    30. else if(slotNumber == 11)
    31. slotPosition = slotGameObject[10].transform.position;
    32. else if(slotNumber == 12)
    33. slotPosition = slotGameObject[11].transform.position;
    34. else if(slotNumber == 13)
    35. slotPosition = slotGameObject[12].transform.position;
    36. else if(slotNumber == 14)
    37. slotPosition = slotGameObject[13].transform.position;
    38. else if(slotNumber == 15)
    39.  
    40. slotPosition = slotGameObject[14].transform.position;
    41. else if(slotNumber == 16)
    42. slotPosition = slotGameObject[15].transform.position;
    43.  
    44. var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    45.  
    46. for(var touch : Touch in Input.touches)
    47. {
    48. if (Physics.Raycast (ray, hit, 100))
    49. {
    50. if(touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Began)
    51. {
    52. transform.position = Camera.main.ScreenToWorldPoint(new
    53. Vector3 (touch.position.x, touch.position.y, 10));
    54. }
    55. else
    56. {
    57.  
    58. }
    59.  
    60. }
    61.  
    62. }
    63.  
    64. }
    65.  
    66. function OnGUI()
    67. {
    68. GUILayout.BeginArea(Rect(Screen.width*0.9-200,Screen.height*0.9-200,200,200));
    69. GUILayout.BeginVertical();
    70. if(GUILayout.Button("W",GUILayout.Width(50),GUILayout.Height(50)))
    71. PlayerMove("Up");
    72. GUILayout.BeginHorizontal();
    73. if(GUILayout.Button("A",GUILayout.Width(50),GUILayout.Height(50)))
    74. PlayerMove("Left");
    75. if(GUILayout.Button("D",GUILayout.Width(50),GUILayout.Height(50)))
    76. PlayerMove("Right");
    77. GUILayout.EndHorizontal();
    78. if(GUILayout.Button("S",GUILayout.Width(50),GUILayout.Height(50)))
    79. PlayerMove("Down");
    80. GUILayout.EndVertical();
    81. GUILayout.EndArea();
    82. }
    83.  
    84. function PlayerMove(Dir : String)
    85. {
    86. if(Dir == "Up")
    87. {
    88. transform.Translate(Vector3(0,0,2.45));
    89. }
    90. if(Dir == "Down")
    91. {
    92. transform.Translate(Vector3(0,0,-2.45));
    93. }
    94. if(Dir == "Left")
    95. {
    96.  
    97. transform.Translate(Vector3(-2.45,0,0));
    98.  
    99. }
    100. if(Dir == "Right")
    101. {
    102. transform.Translate(Vector3(2.45,0,0));
    103. }
    104.  
    105. }
    Thank you so much!
     
  2. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
  3. killerz

    killerz

    Joined:
    Aug 28, 2010
    Posts:
    32
    thanks for reply, but i know how move a cube with touch, but i want move a cube in grid like blockout. Please can you help me?