have an obvect rotate on Z to coincide with mouse movement - but I can't get the code right for a different object to rotate on X
just as the title says. I figured out how to get an object to rotate on Z but when I try to alter the code to rotate on X I keep getting the error cs(20,67): error CS1026: Unexpected symbol ,', expecting
)'. I can't stare at it any more please help - tell we why the first line works and the second line does not
//this code rotates an object on its Z axis with mouse movement
if(Input.GetAxis("Mouse X")<0 || (Input.GetAxis("Mouse X")>0))
{
transform.Rotate(0, 0, -(Input.GetAxis("Mouse X")) * Time.deltaTime * speed );
//and this code should rotate an object on X axis. or so I thought
if(Input.GetAxis("Mouse X")<0 || (Input.GetAxis("Mouse X")>0))
{
transform.Rotate((Input.GetAxis("Mouse X"),0,0)* Time.deltaTime * speed ));
}
Answer by shadowpuppet · Jun 18, 2017 at 05:38 PM
The heck with! easier to just parent the object to an empty gameObject orientated in such a way that I can rotate in Z again
Answer by CurtMC · Oct 31, 2017 at 05:50 AM
You have an extra close bracket ')' on the second part of your coding. Also, I'm not sure if you made a mistake writing your code, but the first part is missing a curly brace '}' as well.
Answer by lll4louis · Apr 20, 2019 at 03:34 PM
The following is auto-spin, still hope it helps.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotation : MonoBehaviour
{
public int rotateSpeed = 5;
void Update()
{
transform.Rotate(rotateSpeed * Time.deltaTime, 0, 0);
}
}
only on z-axis
For x-axis, change the void Update
void Update()
{
transform.Rotate(rotateSpeed * Time.deltaTime, 0, 0);
}