This is what i tried so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public struct SpinableObject
{
public Transform t;
public float rotationSpeed;
public float minSpeed;
public float maxSpeed;
public float speedRate;
[HideInInspector]
public bool slowDown;
}
public class SpinObject : MonoBehaviour
{
private bool slowDown = false;
public float rotationSpeed;
public float slowdownMax;
public float slowdownMin;
public GameObject[] objectsToRotate;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
for (int i = 0; i < objectsToRotate.Length; i++)
{
SpinableObject spinableObject = objectsToRotate*;*
if(spinableObject.rotationSpeed > spinableObject.maxSpeed)
spinableObject.slowDown = true;
else if (spinableObject.rotationSpeed < spinableObject.minSpeed)
spinableObject.slowDown = false;
spinableObject.rotationSpeed = (spinableObject.slowDown) ? spinableObject.rotationSpeed - 0.1f : spinableObject.rotationSpeed + 0.1f;
spinableObject.t.Rotate(Vector3.forward, Time.deltaTime * spinableObject.rotationSpeed);
}
}
}
But i’m getting error on:
SpinableObject spinableObject = objectsToRotate*;*
The error is on the: objectsToRotate
*> Cannot implicitly convert type ‘UnityEngine.GameObject’ to ‘SpinableObject’ *
So first how can i fix the error ?
Second how can i make it instead using struct to use two classes:
A class with its own function to manage the rotation and another one to indicate whether the object should accelerate or decelerate