Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Input.GetTouch and Input.GetMouse

Discussion in 'Scripting' started by Flumobil, Oct 3, 2014.

  1. Flumobil

    Flumobil

    Joined:
    Jun 6, 2014
    Posts:
    8
    Hello,

    I would like your help to change the shape of the object manipulation. Change getMouseButton that rotates left and right, doing the same with getTouch.

    how it works and how should I do?

    Code (CSharp):
    1. #pragma strict
    2.  
    3. public var moveSpeed : float = 10f;
    4. public var turnSpeed : float = 50f;
    5.  
    6.  
    7. function Update ()
    8. {
    9.    
    10.     if(Input.GetMouseButton(0))
    11.         transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
    12.    
    13.     if(Input.GetMouseButton(1))
    14.         transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
    15. }
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. Flumobil

    Flumobil

    Joined:
    Jun 6, 2014
    Posts:
    8
  4. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Yes, look at your post
     
  5. Flumobil

    Flumobil

    Joined:
    Jun 6, 2014
    Posts:
    8
    yes, I did so and got no result.

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. public var moveSpeed : float = 10f;
    4. public var turnSpeed : float = 50f;
    5.  
    6.  
    7. function Update ()
    8. {
    9.    
    10.     if (Input.touchCount > 0 &&
    11.           Input.GetTouch(0).phase == TouchPhase.Moved) {
    12.         transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
    13.         transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
    14.        
    15.        }
    16. }
     
  6. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Have you tried other touch phases
    Have you tried debugs to see if its actually calling
     
  7. MegadethRocks

    MegadethRocks

    Joined:
    Dec 12, 2009
    Posts:
    162
    Your last code block isn't going to work. You rotate by -turnSpeed and then immediately rotate by turnSpeed. This is going to make it look like nothing happened. You will need to come up with logic to decide which of the two you should do.