Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by unity_9d5-VgjizaCUeQ · Dec 26, 2017 at 09:48 AM · androidinputsearch

I can't find the inputs

Hello I have downloaded a script to move my cube around but when I want to convert it to android I can't find the inputs to change them. On pc the cube moves with the left and right arrow. You can see that my touch screen setting are there (44 - 55). How do I fix this?

 {
 
     public float rotationPeriod = 0.3f;     // 隣に移動するのにかかる時間
     public float sideLength = 1f;           // Cubeの辺の長さ
     public event System.Action OnPlayerDeath;
 
     bool isRotate = false;                  // Cubeが回転中かどうかを検出するフラグ
     float directionX = 0;                   // 回転方向フラグ
     float directionZ = 0;                   // 回転方向フラグ
 
     Vector3 startPos;                       // 回転前のCubeの位置
     float rotationTime = 0;                 // 回転中の時間経過
     float radius;                           // 重心の軌道半径
     Quaternion fromRotation;                // 回転前のCubeのクォータニオン
     Quaternion toRotation;                  // 回転後のCubeのクォータニオン
 
     // Use this for initialization
     void Start()
     {
 
         // 重心の回転軌道半径を計算
         radius = sideLength * Mathf.Sqrt(2f) / 2f;
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
         float x = 0;
         float y = 0;
 
         // キー入力を拾う。
         
         if (x == 0)
         {
             y = Input.GetAxisRaw("Horizontal");
         }
         foreach (Touch touch in Input.touches)
         {
             if ((touch.position.x > Screen.width / 2) && (touch.phase == TouchPhase.Began))
             {
               
             }
 
             if ((touch.position.x > Screen.width / 2) && (touch.phase == TouchPhase.Began))
             {
                
             }
         }
 
 
         // キー入力がある かつ Cubeが回転中でない場合、Cubeを回転する。
         if ((x != 0 || y != 0) && !isRotate)
         {
             directionX = -y;                                                             // 回転方向セット (x,yどちらかは必ず0)
             directionZ = -x;                                                             // 回転方向セット (x,yどちらかは必ず0)
             startPos = transform.position;                                              // 回転前の座標を保持
             fromRotation = transform.rotation;                                          // 回転前のクォータニオンを保持
             transform.Rotate(directionZ * 90, 0, directionX * 90, Space.World);     // 回転方向に90度回転させる
             toRotation = transform.rotation;                                            // 回転後のクォータニオンを保持
             transform.rotation = fromRotation;                                          // CubeのRotationを回転前に戻す。(transformのシャローコピーとかできないんだろうか…。)
             rotationTime = 0;                                                           // 回転中の経過時間を0に。
             isRotate = true;                                                            // 回転中フラグをたてる。
         }
     }
 
     void FixedUpdate()
     {
 
         if (isRotate)
         {
 
             rotationTime += Time.fixedDeltaTime;                                    // 経過時間を増やす
             float ratio = Mathf.Lerp(0, 1, rotationTime / rotationPeriod);          // 回転の時間に対する今の経過時間の割合
 
             // 移動
             float thetaRad = Mathf.Lerp(0, Mathf.PI / 2f, ratio);                   // 回転角をラジアンで。
             float distanceX = -directionX * radius * (Mathf.Cos(45f * Mathf.Deg2Rad) - Mathf.Cos(45f * Mathf.Deg2Rad + thetaRad));      // X軸の移動距離。 -の符号はキーと移動の向きを合わせるため。
             float distanceY = radius * (Mathf.Sin(45f * Mathf.Deg2Rad + thetaRad) - Mathf.Sin(45f * Mathf.Deg2Rad));                        // Y軸の移動距離
             float distanceZ = directionZ * radius * (Mathf.Cos(45f * Mathf.Deg2Rad) - Mathf.Cos(45f * Mathf.Deg2Rad + thetaRad));           // Z軸の移動距離
             transform.position = new Vector3(startPos.x + distanceX, startPos.y + distanceY, startPos.z + distanceZ);                       // 現在の位置をセット
 
             // 回転
             transform.rotation = Quaternion.Lerp(fromRotation, toRotation, ratio);      // Quaternion.Lerpで現在の回転角をセット(なんて便利な関数)
 
             // 移動・回転終了時に各パラメータを初期化。isRotateフラグを下ろす。
             if (ratio == 1)
             {
                 isRotate = false;
                 directionX = 0;
                 directionZ = 0;
                 rotationTime = 0;
             }
         }
     }
     void OnTriggerEnter(Collider triggerCollider)
     {
         if (triggerCollider.tag == "Falling Block")
         {
 
 
             if (OnPlayerDeath != null)
             {
                 OnPlayerDeath();
             }
            
             Destroy (gameObject);
         }
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by unity_9d5-VgjizaCUeQ · Dec 26, 2017 at 10:23 AM

English version

 public class move1 : MonoBehaviour
 {
 
     public float rotationPeriod = 0.3f;     // Time taken to move next to
     public float sideLength = 1f;           // Edge length of Cube
     public event System.Action OnPlayerDeath;
 
     bool isRotate = false;                  // Flag to detect whether the Cube is rotating or not
     float directionX = 0;                   // Rotation direction flag
     float directionZ = 0;                   // Rotation direction flag
 
     Vector3 startPos;                       // Position of Cube before rotation
     float rotationTime = 0;                 // Time lapse during rotation
     float radius;                           // Orbital radius of center of gravity
     Quaternion fromRotation;                // Quotanion of Cube before rotation
     Quaternion toRotation;                  // Quotanion of Cube after rotation
 
 
     // Use this for initialization
     void Start()
     {
 
         // Calculate rotational orbit radius of center of gravity
         radius = sideLength * Mathf.Sqrt(2f) / 2f;
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
         float x = 0;
         float y = 0;
 
         // pick up the key input.。
 
         if (x == 0)
         {
             y = Input.GetAxisRaw("Horizontal");
         }
         foreach (Touch touch in Input.touches)
         {
             if ((touch.position.x < Screen.width / 2) && (touch.phase == TouchPhase.Began))
             {
                 ;
             }
 
             if ((touch.position.x > Screen.width / 2) && (touch.phase == TouchPhase.Began))
             {
                 ;
             }
         }
 
         // If there is a key input and the Cube is not rotating, rotate the Cube.        
         if ((x != 0 || y != 0) && !isRotate)
         {
             directionX = -y;                                                             // Rotation direction set (either x or y must be 0)
             directionZ = -x;                                                             // Rotation direction set (either x or y must be 0)
             startPos = transform.position;                                              // Maintain coordinates before rotation
             fromRotation = transform.rotation;                                          // Keep quaternion before rotation
             transform.Rotate(directionZ * 90, 0, directionX * 90, Space.World);         // Rotate 90 degrees in the direction of rotation
             toRotation = transform.rotation;                                            // Retain quaternion after rotation
             transform.rotation = fromRotation;                                          // Return Cube Rotation before rotation. (Is not it a shallow copy of transform or ...?)
             rotationTime = 0;                                                           // The elapsed time during rotation is set to 0
             isRotate = true;                                                            // Make a rotating flag
         }
     }
 
     void FixedUpdate()
     {
 
         if (isRotate)
         {
 
             rotationTime += Time.fixedDeltaTime;                                    // Increase elapsed time
             float ratio = Mathf.Lerp(0, 1, rotationTime / rotationPeriod);          // Percentage of current elapsed time relative to time of rotation
 
             // Move
             float thetaRad = Mathf.Lerp(0, Mathf.PI / 2f, ratio);                   // Rotation angle in radians
             float distanceX = -directionX * radius * (Mathf.Cos(45f * Mathf.Deg2Rad) - Mathf.Cos(45f * Mathf.Deg2Rad + thetaRad));      // Distance traveled on X axis. The sign of - is for aligning the direction of movement with the key.
             float distanceY = radius * (Mathf.Sin(45f * Mathf.Deg2Rad + thetaRad) - Mathf.Sin(45f * Mathf.Deg2Rad));                        // Y axis movement distance
             float distanceZ = directionZ * radius * (Mathf.Cos(45f * Mathf.Deg2Rad) - Mathf.Cos(45f * Mathf.Deg2Rad + thetaRad));           // Z axis travel distance
             transform.position = new Vector3(startPos.x + distanceX, startPos.y + distanceY, startPos.z + distanceZ);                       // Set the current position
 
             // rotation
             transform.rotation = Quaternion.Lerp(fromRotation, toRotation, ratio);      // Set current rotation angle with Quaternion.Lerp (what a useful function)
 
             // Initialize each parameter at the end of movement / rotation.Lower the isRotate flag.
             if (ratio == 1)
             {
                 isRotate = false;
                 directionX = 0;
                 directionZ = 0;
                 rotationTime = 0;
             }
         }
     }
     void OnTriggerEnter(Collider triggerCollider)
     {
         if (triggerCollider.tag == "Falling Block")
         {
 
 
             if (OnPlayerDeath != null)
             {
                 OnPlayerDeath();
             }
            
             Destroy (gameObject);
         }
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

164 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android input multi touch 2 Answers

Cross-Platform User-Defined Keys? 0 Answers

Using the Volume Control Buttons On Mobile Devices 0 Answers

Is there a way to access GPS data/Input.Location without wifi? On my device (S7) it only works with. 0 Answers

Gamestop Android Wireless Game Controller 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges