[Android] Can anyone help me with the Platform script??(solved)

Updated on November 9, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on November 9, 2017

i am trying to make Platform Mechanics of Game Elevator Ball for android(try the link below, works for both android and pc) But i am not able to make platform Mechanics exactly like that!! can anyone please help me with that!!

 

 
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PlatformMechanics : MonoBehaviour {
 
Vector2 firstpos;
 Vector2 secpos;
 Vector2 lastpos;
 private int touchNum = 0;
 private bool leftisfirst = false;
 Vector2 SecondTouch;
 Vector2 firstTouch;
 float RotateAmount = 200f;
 private void Start()
 {
 StartCoroutine(Movement());
 }
 private IEnumerator Movement()
 {
 while (true)
 {
 GetfingerTouches();
 yield return 0;
 }
 }
 
private void GetfingerTouches()
 {
 
if (Input.touchCount > 0 && Input.touchCount < 3)
 {
 Touch t1, t2 = Input.GetTouch(0);
 t1 = Input.GetTouch(0);
 if (Input.touchCount > 1)
 t2 = Input.GetTouch(1);
 if (t1.position.x < Screen.width / 2 || t2.position.x < Screen.width / 2)
 {
#region Getting FirstTouch
 if (t1.phase == TouchPhase.Began)
 {
 firstTouch = (Vector2)t1.position;
 Debug.Log(firstTouch);
 }
 else if(t2.phase == TouchPhase.Began)
 {
 firstTouch = (Vector2)t2.position;
 Debug.Log(firstTouch);
 }
#endregion
 if (t1.position.y > firstTouch.y)
 {
 RotateAmount = t1.position.y / 2;
 RollUp(-RotateAmount);
 }
 else if (t1.position.y < firstTouch.y)
 {
 RotateAmount = t1.position.y / 2;
 RollUp(RotateAmount * 2);
 }
 }
 if (t1.position.x > Screen.width / 2 || t2.position.x > Screen.width / 2)
 {
#region Getting SecondTouch
 if (t2.phase == TouchPhase.Began)
 {
 SecondTouch = (Vector2)t1.position;
 Debug.Log(SecondTouch);
 }
 else if(t2.phase == TouchPhase.Began)
 {
 SecondTouch = (Vector2)t2.position;
 Debug.Log(SecondTouch);
 }
#endregion
 // if (Input.touchCount > 1)
 if (t2.position.y > firstTouch.y)
 {
 RotateAmount = t2.position.y / 2;
 RollUp(RotateAmount);
 }
 else if (t2.position.y < firstTouch.y / 2)
 {
 RotateAmount = t2.position.y / 2;
 RollUp(-RotateAmount * 2);
 }
 }
 
}
 }
 
private void RollUp(float rot)
 {
 transform.Rotate(0, 0, rot / 3 * Time.deltaTime * 5);
 }
 
}
 

 

https://www.yiv.com/Elevator-Ball

  • Liked by
Reply