How to rotate just the object being touched in Unity?

| | August 18, 2015

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?

Leave a Reply