给拾取的物体添加旋转效果
void Update () {
transform.Rotate(0,-25*Time.deltaTime,0,Space.Self);
}
给拾取物体添加碰撞效果
0.得关掉刚体的重力效果;
1.给玩家拾取的物体计数
2.销毁物体
//该脚本在拾取物上
void OnTriggerEnter (Collider col) {
if (col.gameObject.tag == "Player") {
col.gameObject.SendMessage("setCellCount");
Destroy(gameObject);
}
}
//该脚本在主角脚本上
void setCellCount(){
cellCount++;
AudioSource.PlayClipAtPoint (collectSound, transform.position);
}
拾取一定数量的物体方可进入房屋
//该脚本在房屋上
void OnTriggerEnter (Collider col) {
if (col.gameObject.tag == "Player") {
cellTarget=Goods.cellCount;
if(cellTarget==2){
transform.FindChild("door").SendMessage("doorcheck");}
}
拾取数量改变,界面提示的图标改变
1.添加一个rawImage物体,修改纹理
2.在角色的Goods脚本中申请一个数组用来保存贴图,在属性面板传贴图
public Texture2D[] textures;
3.在代码中修改rawImage的贴图
public RawImage powerTexture;
powerTexture.texture=textures[cellCount];
动态更改指示器的纹理
public Renderer chargeMeterMaterial;
chargeMeterMaterial.material.mainTexture = generatorTextures [cellCount];
改变灯光
public Light pl;
pl.color = Color.green;
当电池数量不足时给予玩家提示
public Text t;
t.text="还未收集齐能量源";
t.enabled=false;
获取界面UI物体注意事项
using UnityEngine.UI;