Question by
ViolentMuffin · Feb 10 at 12:19 PM ·
c#rotationrandom
Rotating object - make program select one value and rotate the object by this value.
Hi! So I have this code to rotate an object by a certain random value:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cube : MonoBehaviour
{
public MeshRenderer Renderer;
public Vector3 position = new Vector3(3, 4, 1);
public Vector3 scale = new Vector3(1, 1, 1);
public float scaleCoefficient = 1.3f;
public Color color = new Color(0.5f, 1.0f, 0.3f, 0.4f);
private float rotationInterval = 1f;
void Start()
{
transform.position = position;
transform.localScale = scale * scaleCoefficient;
Material material = Renderer.material;
material.color = color;
}
void Update()
{
int rotationX = Random.Range(-11, 11);
float rotationY = 0f;
float rotationZ = 0f;
transform.Rotate(rotationX * Time.deltaTime, rotationY * Time.deltaTime, rotationZ * Time.deltaTime);
}
}
But it seems that the program selects a different value every second, so my object doesn't rotate but jitters in place while the program selects random numbers between minus and plus values. What can I do to make the program select one value and rotate the object by that value at the start of the scene?
Comment
Your answer

Follow this Question
Related Questions
Stop rotating after falling down 1 Answer
How to put limit for Transform.rotate in unity 2d 1 Answer
Rotate an image through a byte array? 1 Answer
[C#] Rotate player to camera forward look 0 Answers
Can't change rotation? 0 Answers