using UnityEngine;
using System.Collections;
public class Tool : MonoBehaviour {
float hor;
Vector3 moveDir;
public float moveSpeed = 3f;
int score = 0;
void Update()
{
hor = Input.GetAxis ("Horizontal");
//获取移动方向向量
moveDir = hor * Vector3.right;
//移动
transform.position += moveDir * Time.deltaTime * moveSpeed;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Gold") {
Destroy (other.gameObject);
Debug.Log (++score);
}
}
}
using UnityEngine;
using System.Collections;
public class GoldCreater : MonoBehaviour {
//金币预设体
public GameObject goldPrefab;
//生成金币的时间间隔
public float interval = 1f;
//计时器
private float timer;
//索引号
private int index;
void Update()
{
//计时器计时
timer += Time.deltaTime;
//计时完成
if (timer >= interval) {
///TODO:生成金币
GoldInit();
//计时器归零
timer = 0;
}
}
/// <summary>
/// 生成金币
/// </summary>
void GoldInit()
{
//子对象索引号(随机)
index = Random.Range (0, 3);
//生成位置
Vector3 initPos = transform.GetChild (index).position;
//生成金币
Instantiate (goldPrefab, initPos, Quaternion.identity);
}
}
盘子接金币
最新推荐文章于 2023-01-09 14:41:58 发布