1.Vector3坐标
2.地球,月球,太阳的旋转关系
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class spere01 : MonoBehaviour {
public GameObject moon;
public GameObject sun;
// Use this for initialization
void Start () { } // Update is called once per frame
void Update () {
// transform.Rotate(Vector3.up, 2, Space.World);//up表示围绕上面轴旋转
moon.transform.Rotate(, , );//月球自传
transform.Rotate(, , );//地球自转
sun.transform.Rotate(Vector3.up);//太阳自转
moon.transform.RotateAround(transform.position, Vector3.up, );//月亮围绕地球转
transform.RotateAround(sun.transform.position, Vector3.up, );//地球围绕太阳转 }
}
3.UI之游戏界面
登录错误提示:
提示登录失败用:
if (this.gameObject.activeSelf)
{
time += Time.deltaTime;//计时器
if (time > 3)
{
failText.gameObject.SetActive(false);//登录失败消失
time = 0;
}
}
进入游戏就有声音:
slider.maxValue = 100;
slider.minValue = 0;
slider.value = 50;//赋初值
if (toggle.isOn==true)
{ audio.mute = true;//静音
}
else
{
audio.mute = false;
} audio.volume =(float) (slider.value/100);//把音量条的值赋给背景音乐
//总代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI; public class UIcontrol : MonoBehaviour {
public InputField InputUserName;
public InputField InputPassWord;
public Button button;
public GameObject failText;
public Button closeSetting;
public GameObject Panel;
public Slider slider;
public Toggle toggle;
AudioSource audio; // Use this for initialization
void Start () {
InputUserName = InputUserName.GetComponent<InputField>();
InputPassWord = InputPassWord.GetComponent<InputField>();
button = button.GetComponent<Button>();
closeSetting = closeSetting.GetComponent<Button>();
slider = slider.GetComponent<Slider>();
audio = GetComponent<AudioSource>();
slider.maxValue = ;
slider.minValue = ;
slider.value = ; } public void GetButton()
{
if (InputUserName.text == "huangwei" && InputPassWord.text == "")
{
SceneManager.LoadScene();
}
else
{
failText.gameObject.SetActive(true);//登录失败出现
}
}
public void OpenSetting()
{
Panel.gameObject.SetActive(true);//打开设置
}
public void CloseSetting()//关闭设置
{
Panel.gameObject.SetActive(false);
}
// Update is called once per frame
float time; void Update()
{
if (this.gameObject.activeSelf)
{
time += Time.deltaTime;//计时器
if (time > )
{
failText.gameObject.SetActive(false);//登录失败消失
time = ;
}
} if (toggle.isOn==true)
{ audio.mute = true;//静音
}
else
{
audio.mute = false;
} audio.volume =(float) (slider.value/);//把音量条的值赋给背景音乐
}
}
4.进度条slider: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; public class test : MonoBehaviour { Text test01;
int num = ;
float time; public Slider slider;
// Use this for initialization
void Start () {
test01 = this.GetComponent<Text>();
slider = slider.GetComponent<Slider>();
slider.maxValue = ;
slider.value = slider.minValue;
} // Update is called once per frame
void Update () {
time += Time.deltaTime;
//if (time >0.1f)
//{
// num++;
// if (num >100)
// {
// num = 100;
// test01.text = num + " %";
// }
// else
// {
// slider.value = num;
// time = 0;
// } //}
//test01.text = num + " %";
//另一种方法 if (time > )
{
time = ;
}
slider.value = time * ;
test01.text = (int)(time*)+ " %";
}
}
5.
技能冷却:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; public class CoolSkill : MonoBehaviour
{
public Image image;
float time;
float f;
public Text text;
bool b = false;
bool bb = true;
// Use this for initialization
void Start()
{
image = image.GetComponent<Image>();
text = text.GetComponent<Text>();
image.fillAmount = ;//默认可以发出技能
}
public void GetBool()
{
if (bb)//限制技能开启后才能使用
{
b = true;
bb = false;
}
}
// Update is called once per frame
void Update()
{
if (b)
{
time += Time.deltaTime;
if (time <= )//技能控制在5秒冷却
{
f = ( - time);//5秒倒计时
image.fillAmount = (f) / ;//image也在360度递减
text.text = (f).ToString();//文本输出倒计时
if (f < 0.1f && f >= )/控制在0.1秒以内结束时才可以重新开启技能
{
bb = true;//重新开启技能Button可以点击了
}
}
else
{
time = ;//超过5秒后时间置零
b = false;/tton点击后又可以计时了
} } }
}