unity 按下鼠标左键随机生成物体Instantiate
2016-05-11 14:32
489 查看
using UnityEngine;
using System.Collections;
public class CreateObj : MonoBehaviour {
public GameObject car;
public float produceRate = 0.5f;
private float nextProduce = 0;
// Update is called once per frame
void Update()
{
//Fire1默认对应摇杆的0号按键(鼠标左键)
if (Input.GetButton("Fire1") && Time.time > nextProduce)
{
nextProduce = Time.time + produceRate;
//当按下Fire1键时,每0.5秒生成一个汽车.
Vector3 position = new Vector3(Random.Range(-5, 5), 1, Random.Range(-5, 5));
GameObject clone = Instantiate(car, position, car.transform.rotation) as GameObject;
}
}
}
using System.Collections;
public class CreateObj : MonoBehaviour {
public GameObject car;
public float produceRate = 0.5f;
private float nextProduce = 0;
// Update is called once per frame
void Update()
{
//Fire1默认对应摇杆的0号按键(鼠标左键)
if (Input.GetButton("Fire1") && Time.time > nextProduce)
{
nextProduce = Time.time + produceRate;
//当按下Fire1键时,每0.5秒生成一个汽车.
Vector3 position = new Vector3(Random.Range(-5, 5), 1, Random.Range(-5, 5));
GameObject clone = Instantiate(car, position, car.transform.rotation) as GameObject;
}
}
}
相关文章推荐
- unity 通过键盘控制角色的移动和旋转
- Part2:Unity学习笔记十二 - Space Shooter(从视频最后一课向Done_Main.unity场景修改的过程)
- unity 根据鼠标的移动来旋转物体Rotate
- unity 相机平滑的接近物体脚本 Mathf.Smooth
- unity 用鼠标控制相机绕着物体旋转脚本
- Unity中的Path对应各平台中的Path
- unity 在移动平台中,文件操作路径详解
- 浅谈unity3d中使用MVC框架模式
- Android Studio 2.1 和 Unity3D 5.3.4 交互(二)
- Unity3D中uGUI事件系统简述及使用方法总结
- Unity3.X 笔记01
- 旋转角色
- Unity3d Realtime Dynamic Clouds Rendering
- Unity Shaders and Effects Cookbook (7-1) 在Surface Shader 中 访问 顶点颜色
- unity 的内存管理
- unity+Cardboard SDK VR开发Cardboard Unity SDK讲解
- unity+Cardboard SDK VR开发教程
- 一个unity 牛的博客网址
- Unity打包Android备忘
- <Unity-UGUI>使用Mask, 正确的裁减非默认材质UI对象