盘子接金币

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);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值