increase rotating speed at specific score

Hello
I am working on a basic project, and i am facing a problem i wish i can have support to solve it.
My game is a rotating wheel with score decreasing from 99 to 0 with a speed 120.
the problem i am facing is that i am failing to add a feature which is after score become 90, the speed of the rotating wheel increase to 150 an than after reaching score 80 i want the speed to be 190.

i failed to make those additions, and i want your help. below you can find my spin code without any errors.

using UnityEngine;
using System.Collections;

public class Spin : MonoBehaviour {
	public float speed = 120f;
	private float direction = 1; //1: rotate clk, 0: rotate cclk
	
	// Update is called once per frame
	void FixedUpdate () {
		//only rotate when in playing mode
		if (GameManager.CurrentState == GameManager.GameState.Playing)
			transform.Rotate (Vector3.forward, direction * speed * Time.fixedDeltaTime);
	}

	//called by Picker.cs
	public void ChangeDirection(){
		direction *= -1;
	}
}

If you can help me with additions i should make to get best result
thanks in advance for your support.

hi @Beginner111 You could solve your problem by implementing a if-elseif block of code in your Update method.Something like this could work:-

if(score>90)
speed=120f;
else if(score>80)
speed=150f;
else if(score>70)
//Set the speed as per your choice.

So I assume you’re having trouble accessing the variable inside GameManager from Spin. You can use FindObjectOfType() inside Start() inside Spin script.

private GameManager gameManager;

void Start()
{
    gameManager = FindObjectOfType<GameManager>();
}

You can later access GameManager’s variables (if they’re public, call the accessor method if they’re private) by doing

int score = gameManager.intCountDownFrom; //I assume this is your score variable

Of course, you can do it the other way around too. By doing FindObjectOfType<>() inside GameManager instead and grab Spin’s speed variable from there. Up to you.

If you need more help, do ask :slight_smile:
@Beginner111