UGUI_创建旋转物体,使用Slider控制小球旋转速度

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 
 5 public class Player : MonoBehaviour {
 6     public float speed = 50f;
 7     // Use this for initialization
 8     void Start () {
 9         
10     }
11     
12     // Update is called once per frame
13     void Update () {
14         transform.Rotate(Vector3.up,speed *Time.deltaTime);
15     }
16     public void ChangeSpeed(float newSpeed)
17     {
18         this.speed = newSpeed; 
19     }
20 }

player空物体,挂载player脚本;

Canvas下Slider,OnValueChanged 事件处理:  Player物体+(player脚本下的)ChangeSpeed方法。

posted @ 2018-04-28 15:50  MR_L先生  阅读(407)  评论(0编辑  收藏  举报