How to rotate just the object being touched in Unity?

by muhkuhgd   Last Updated July 13, 2019 11:13 AM

For my first steps in Unity I am just trying to rotate some squares when I touch them.

 using UnityEngine;
using System.Collections;

public class testskript2 : MonoBehaviour {

    // Use this for initialization
    void Start () {
        //transform.Rotate(Vector3.forward * 2 * 100);
    }

    // Update is called once per frame
    void Update () {
        if (Input.touchCount == 1) {
            Ray r = camera.ScreenPointToRay(new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y));
            RaycastHit hit0;
            if (Physics.Raycast(r, out hit0, 100f)) {
            transform.Rotate(Vector3.forward * Time.deltaTime * 100);
        }
    }
}
}

It isn't working this way. Any tips?



Related Questions


How to move gameobject with touch on Android

Updated May 23, 2019 14:13 PM

(Unity 5) Weird Touch Behavior

Updated March 24, 2017 17:13 PM

How does Unity input work with touchscreens

Updated September 01, 2017 17:13 PM


Unable to destroy collider Unity3d

Updated May 28, 2019 08:13 AM