Hello I recently started using unity and I wanted to create an AR application for my school project. For one of my objects, I wanted it to rotate on the ‘z’ axis when I tap on my phone’s touch screen. I managed to get an image to pop up as well as an audio clip, but I can’t find anything that can help me with my rotation problem.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Imagecon : MonoBehaviour
{
public AudioClip[] aClips;
public AudioSource myAudioSource;
string btnName;
public Image image;
int _rotationSpeed = 15;
// Use this for initialization
void Start()
{
myAudioSource = GetComponent<AudioSource>();
image.enabled = false;
}
// Update is called once per frame
void Update()
{
if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit Hit;
if (Physics.Raycast(ray, out Hit))
{
btnName = Hit.transform.name;
switch (btnName)
{
case "Standy_Button":
myAudioSource.clip = aClips[0];
myAudioSource.Play();
image.enabled = !image.enabled;
break;
case "Sphere":
myAudioSource.clip = aClips[1];
myAudioSource.Play();
break;
case "Arrow_Pointing_Right":
transform.Rotate(0, _rotationSpeed * Time.deltaTime, 0);
break;
default:
break;
}
}
}
}
}