1: var ballObj : GameObject;
2: 3: function Start() 4: {5: ballObj = GameObject.Find("Ball");
6: } 7: 8: function FixedUpdate () 9: { 10: detectGetAxis(); 11: } 12: 13: function detectGetAxis() 14: {15: var tempconV = Input.GetAxis ("Vertical");
16: 17: var tempconH = Input.GetAxis ("Horizontal");
18: 19: print("tempconV:"+tempconV);
20: 21: print("tempconH:"+tempconH);
22: 23: ballObj.rigidbody.AddForce(tempconH*20,0,tempconV*20); 24: } 1: function detectGetKey() 2: { 3: 4: var tempbutton = Input.GetKey(KeyCode.A);
5: 6: if(tempbutton)
7: {8: print("tempbutton:"+tempbutton);
9: } 10: 11: } 1: Input.GetKeyDown(KeyCode.A); 1: function detectGetMouseButton() 2: {3: //mouse left button
4: var tempmousebutton = Input.GetMouseButton(0);
5: 6: if(tempmousebutton)
7: {8: print("tempmousebutton:"+tempmousebutton);
9: } 10: 11: } 1: Input.GetMouseButtonDown(0); 1: function detectAcceleration() 2: {3: var tempx = Input.acceleration.x;
4: var tempy = Input.acceleration.y;
5: var tempz = Input.acceleration.z;
6: 7: ballObj.rigidbody.AddForce(-tempy*30,0,tempx*30); 8: 9: }1: var ballObj : GameObject;
2: 3: var tempLjoystick : Joystick;
4: var tempRjoystick : Joystick;
5: 6: function Start() 7: {8: ballObj = GameObject.Find("Ball");
9: 10: tempLjoystick = GameObject.Find("LeftJoystick").GetComponent(Joystick);
11: tempRjoystick = GameObject.Find("RightJoystick").GetComponent(Joystick);
12: } 1: function detectJoyStick() 2: { 3: ballObj.rigidbody.AddForce(tempLjoystick.position.x*10,0,tempLjoystick.position.y*10); 4: }1: function detectTouch(a:int)
2: {3: //case 0
4: if(a==0)
5: {6: if(Input.touchCount>0)
7: {8: var touch1 = Input.GetTouch(0);
9: 10: if(touch1.position.x < Screen.width/2 && touch1.position.y < Screen.height/2)
11: { 12: ballObj.rigidbody.AddForce(-20,0,-20); 13: }14: else if(touch1.position.x < Screen.width/2 && touch1.position.y > Screen.height/2)
15: { 16: ballObj.rigidbody.AddForce(-20,0,20); 17: }18: else if(touch1.position.x > Screen.width/2 && touch1.position.y < Screen.height/2)
19: { 20: ballObj.rigidbody.AddForce(20,0,-20); 21: }22: else if(touch1.position.x > Screen.width/2 && touch1.position.y > Screen.height/2)
23: { 24: ballObj.rigidbody.AddForce(20,0,20); 25: } 26: } 27: 28: }29: //case 1
30: else if(a==1)
31: {32: var temptouchs = Input.touches;
33: 34: if(temptouchs.Length>0)
35: { 36: if(temptouchs[0].position.x < Screen.width/2 && temptouchs[0].position.y < Screen.height/2)
37: { 38: ballObj.rigidbody.AddForce(-20,0,-20); 39: }40: else if(temptouchs[0].position.x < Screen.width/2 && temptouchs[0].position.y > Screen.height/2)
41: { 42: ballObj.rigidbody.AddForce(-20,0,20); 43: }44: else if(temptouchs[0].position.x > Screen.width/2 && temptouchs[0].position.y < Screen.height/2)
45: { 46: ballObj.rigidbody.AddForce(20,0,-20); 47: }48: else if(temptouchs[0].position.x > Screen.width/2 && temptouchs[0].position.y > Screen.height/2)
49: { 50: ballObj.rigidbody.AddForce(20,0,20); 51: } 52: } 53: 54: } 55: 56: } 1: function detectTouch() 2: {3: if(Input.touchCount>0)
4: {5: var touch1 = Input.GetTouch(0);
6: 7: if(touch1.phase==TouchPhase.Began)
8: {9: //action
10: } 11: } 12: }1: //#pragma strict
2: 3: //Ball
4: var ballObj : GameObject;
5: 6: //Joystick use
7: var tempLjoystick : Joystick;
8: var tempRjoystick : Joystick;
9: 10: function Start() 11: {12: ballObj = GameObject.Find("Ball");
13: 14: tempLjoystick = GameObject.Find("LeftJoystick").GetComponent(Joystick);
15: tempRjoystick = GameObject.Find("RightJoystick").GetComponent(Joystick);
16: 17: } 18: 19: function Update () 20: { 21: detectTouch(0); 22: } 23: 24: //Get Axis
25: function detectGetAxis() 26: {27: var tempconV = Input.GetAxis ("Vertical");
28: 29: var tempconH = Input.GetAxis ("Horizontal");
30: 31: print("tempconV:"+tempconV);
32: 33: print("tempconH:"+tempconH);
34: 35: ballObj.rigidbody.AddForce(tempconH*20,0,tempconV*20); 36: } 37: 38: //Get KeyBoard
39: function detectGetKey() 40: { 41: 42: var tempbutton = Input.GetKeyDown(KeyCode.A);
43: 44: if(tempbutton)
45: {46: print("tempbutton:"+tempbutton);
47: } 48: 49: } 50: 51: //Get MouseButton
52: function detectGetMouseButton() 53: {54: //mouse left button
55: var tempmousebutton = Input.GetMouseButtonDown(0);
56: 57: if(tempmousebutton)
58: {59: print("tempmousebutton:"+tempmousebutton);
60: } 61: 62: } 63: 64: function detectAcceleration() 65: {66: var tempx = Input.acceleration.x;
67: var tempy = Input.acceleration.y;
68: var tempz = Input.acceleration.z;
69: 70: ballObj.rigidbody.AddForce(-tempy*30,0,tempx*30); 71: 72: } 73: 74: function detectJoyStick() 75: { 76: ballObj.rigidbody.AddForce(tempLjoystick.position.x*10,0,tempLjoystick.position.y*10); 77: } 78: 79: function detectTouch(a:int)
80: { 81: 82: //case 0
83: if(a==0)
84: {85: if(Input.touchCount>0)
86: {87: var touch1 = Input.GetTouch(0);
88: 89: if(touch1.position.x < Screen.width/2 && touch1.position.y < Screen.height/2)
90: { 91: ballObj.rigidbody.AddForce(-20,0,-20); 92: }93: else if(touch1.position.x < Screen.width/2 && touch1.position.y > Screen.height/2)
94: { 95: ballObj.rigidbody.AddForce(-20,0,20); 96: }97: else if(touch1.position.x > Screen.width/2 && touch1.position.y < Screen.height/2)
98: { 99: ballObj.rigidbody.AddForce(20,0,-20); 100: }101: else if(touch1.position.x > Screen.width/2 && touch1.position.y > Screen.height/2)
102: { 103: ballObj.rigidbody.AddForce(20,0,20); 104: } 105: } 106: 107: }108: //case 1
109: else if(a==1)
110: {111: var temptouchs = Input.touches;
112: 113: if(temptouchs.Length>0)
114: { 115: 116: if(temptouchs[0].position.x < Screen.width/2 && temptouchs[0].position.y < Screen.height/2)
117: { 118: ballObj.rigidbody.AddForce(-20,0,-20); 119: }120: else if(temptouchs[0].position.x < Screen.width/2 && temptouchs[0].position.y > Screen.height/2)
121: { 122: ballObj.rigidbody.AddForce(-20,0,20); 123: }124: else if(temptouchs[0].position.x > Screen.width/2 && temptouchs[0].position.y < Screen.height/2)
125: { 126: ballObj.rigidbody.AddForce(20,0,-20); 127: }128: else if(temptouchs[0].position.x > Screen.width/2 && temptouchs[0].position.y > Screen.height/2)
129: { 130: ballObj.rigidbody.AddForce(20,0,20); 131: } 132: } 133: 134: } 135: 136: }標籤: 小技巧