Watch Video Tutorial On Youtube
Spinner Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spinner : MonoBehaviour {
public float reducer;
public float multiplier = 1;
bool round1 = false;
public bool isStoped = false;
void Start ()
{
reducer = Random.Range (0.01f, 0.5f);
}
// Update is called once per frameQ
void FixedUpdate () {
if (Input.GetKey (KeyCode.Space))
{
Reset ();
}
if (multiplier > 0)
{
transform.Rotate (Vector3.forward, 1 * multiplier);
} else
{
isStoped = true;
}
if (multiplier < 20 && !round1)
{
multiplier += 0.1f;
} else
{
round1 = true;
}
if (round1 && multiplier > 0)
{
multiplier -= reducer;
}
}
void Reset()
{
multiplier = 1;
reducer = Random.Range (0.01f, 0.5f);
round1 = false;
isStoped = false;
}
}
Needle Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class needle : MonoBehaviour {
public spinner _spinner;
public Text scoretext;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay2D(Collider2D col){
if (!_spinner.isStoped)
return;
scoretext.text = col.gameObject.name;
}
}
thank u man for this gift , just i want to ask u if i want the wheel staring spin only if i click it on a button how i can do that (i know that should to add button to Hierarchy & drop the script spinner to the On Click in Inspector to button. i literally do that but no function showing up )
ReplyDeleteand sorry for this dumbest question i'm new in unity in c# scripting and thank u so much
Idiots! keep rocking!!! May our Fortune spin like a Mad slippery wheel...
Deleteyou have to put that Reset() function in your button clock event.
ReplyDeleteif you are not getting function against script name in click event use public before Reset().
Check my question below plz
DeleteIts works, but at the start it spin without button, woh to fix it? plz help
ReplyDeletenotice that these two value should be
ReplyDeletepublic float multiplier = 0;
bool round1 = true;
and the function should be
public void Reset()
after that you can trigger it by button