这是我的一个多维数据集游戏的代码。其实我想要这样的代码运行如: 当我按“空间”一旦它必须生成一个立方体,目前它生成一个以上的一个时间按下“空间”按钮多个立方体。其次,当我使用箭头键时,它必须从当前站立的那个位置生成立方体,但是暂时它只是从中心生成立方体。脚本问题统一3D
using UnityEngine;
using System.Collections;
public class fire : MonoBehaviour {
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name == "brick" || collision.gameObject.name == "a" || collision.gameObject.name == "b")
{
Destroy(collision.gameObject);
}
}
public float speed;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
transform.Translate(speed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, 0f);
if (Input.GetKey(KeyCode.Space))
{
transform.Translate(speed * Vector3.up * Time.deltaTime);
}
Vector3 temp = transform.position;
if (Input.GetKey(KeyCode.Space))
{
GameObject textObject = (GameObject)Instantiate(Resources.Load("ball"));
}
}
}
你可以***不使用“unityscript”。它被弃用,不起作用,并且正在从Unity中删除。幸运的是,c#实际上对于初学者来说更容易。请享用。 – Fattie
[Unity3d - Input.GetKey可能重复不止一次返回true](http://stackoverflow.com/questions/30727530/unity3d-input-getkey-returns-true-more-than-once) – Fattie