Question by
panoramabeats · Dec 19, 2016 at 12:00 AM ·
scripting problemvariablefloatsliderassign
How to assign slider to float: Spin, on a gameobject
Here is the Spin script attached to a circle object:
using UnityEngine;
using System.Collections;
public class Spin : MonoBehaviour {
public float speed = 10f;
// Update is called once per frame
void Update () {
transform.Rotate (Vector3.forward, speed * Time.deltaTime);
}
}
I've dragged the GameObject ("Radar Main") into the On Value Changed slot. For function, I choose Spin and a list comes up. I've tried different selections, but none of them control 'speed', the only public float/variable in the script. What am I missing? Thanks.
see screenshot: [1]: /storage/temp/84350-screen-shot-2016-12-18-at-35748-pm.png
screen-shot-2016-12-18-at-35748-pm.png
(54.8 kB)
Comment
Best Answer
Answer by iwaldrop · Dec 19, 2016 at 08:18 AM
This is expected; you haven't defined a function which accepts a float value. Try adding the following to your Spin class.
public void SetSpeed(float speed)
{
this.speed = speed;
}
That should adjust the speed as expected, but it's not totally clear that's what you're intending. Either way I hope this helps you do what you're trying to do.