Showing posts with label spinner. Show all posts
Showing posts with label spinner. Show all posts

Sunday, 15 July 2018

How to Make a Wheel of Fortune in Unity 2018 [ free code + assets ]

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;

}

}