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方法。

转载于:https://www.cnblogs.com/NBOWeb/p/8968175.html

你可能感兴趣的:(游戏,c#)