S
S
Slavon72021-05-12 18:19:32
css
Slavon7, 2021-05-12 18:19:32

Why doesn't random time work?

The essence of the task is to make it so that a random number falls out from 0-40. And when it is reached, we rotate the object along the Z axis.

But the problem is
1) For some reason, the object immediately rotates for me (when the scene starts)
And I thought about what I have timer and when it reaches a random value i.e. starttime == random
rotation is performed

I know that the code is clumsy, but I only need performance

Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Randomizzze : MonoBehaviour
{

    private float StartTime;
    public float StartTime2;
    // public float EndTime;

    public GameObject other;

    int exampleno;


    void Start()
    {

        int exampleno = Random.Range(0, 40);

        Debug.Log(exampleno);

    }
    void Update()
    {
        StartTime += Time.deltaTime;
        StartTime2 = Mathf.Round(StartTime);

        

        if (StartTime2 == exampleno)
        {
            
            Quaternion rotationX = Quaternion.AngleAxis(1, Vector3.up);
            transform.rotation *= rotationX;

        }
    }

}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Timofeev, 2018-11-11
@webinar

Then you do not need a bs grid, but a mansory:
https://masonry.desandro.com
bs4 has a similarity:
https://getbootstrap.com/docs/4.0/components/card/...
but it is crooked and only for the first look like

A
Alexander Ananiev, 2021-05-13
@Slavon7

Probably should be replaced with
int exampleno = Random.Range(0, 40);
exampleno = Random.Range(0, 40);

S
Slavon7, 2021-05-13
@Slavon7

Listen, and the object changes three axes (and it’s not clear how it does it)

Quaternion rotationX = Quaternion.AngleAxis(1, Vector3.up); // Тут я менял и Vector3.forward и right и т.д
            transform.rotation = rotationX; // Тут я убрал *= потому что оно вращается одну секунду(обьект так сказать багается)

I need to rotate the object along the X axis, but for some reason I change all the axes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question