The variable globalRotation: public bool globalRotation = false;
In the inspector i see all the time the name Global Rotation but i want to do somehow that when the Global Rotation is checked(true) change the name in the inspector to Global Rotation. When it’s unchecked(false) change the name to Individual Rotation. It’s working fine like that but i think it will be more nice to change the bool name according to it’s mode too and not only the state(false/true).
I want to know when the settings of Global Rotation are on in use change the bool variable name to Global Rotation when the mode when settings are on for the Individual Rotation change the bool variable name to Individual Rotation.
In general how to change the bool variable name in the inspector according to it’s state: true/false ?
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class SpinableObject
{
public Transform t;
public float rotationSpeed;
public float minSpeed;
public float maxSpeed;
public float speedRate;
public bool slowDown;
public void RotateObject()
{
if (rotationSpeed > maxSpeed)
slowDown = true;
else if (rotationSpeed < minSpeed)
slowDown = false;
rotationSpeed = (slowDown) ? rotationSpeed - 0.1f : rotationSpeed + 0.1f;
t.Rotate(Vector3.forward, Time.deltaTime * rotationSpeed);
}
}
public class SpinObject : MonoBehaviour
{
[SerializeField]
[Header("Global Rotation")]
[Space(5)]
public float rotationSpeed;
public float minSpeed;
public float maxSpeed;
public float speedRate;
public bool slowDown;
public GameObject[] allObjects;
[Space(5)]
[Header("Rotation Mode")]
public bool globalRotation = false;
[Header("Individual Rotation")]
[Space(3)]
public SpinableObject[] individualObjects;
private void Start()
{
allObjects = GameObject.FindGameObjectsWithTag("Propeller");
}
// Update is called once per frame
void Update()
{
if (globalRotation == false)
{
foreach (var spinner in individualObjects)
spinner.RotateObject();
}
else
{
for (int i = 0; i < allObjects.Length; i++)
{
RotateAllObjects(allObjects*.transform);*
}
}
}
private void RotateAllObjects(Transform t)
{
if (rotationSpeed > maxSpeed)
slowDown = true;
else if (rotationSpeed < minSpeed)
slowDown = false;
rotationSpeed = (slowDown) ? rotationSpeed - 0.1f : rotationSpeed + 0.1f;
t.Rotate(Vector3.forward, Time.deltaTime * rotationSpeed);
}
}