HY 我想制作游戏,我想在哪里开始我的迷你高尔夫游戏... 所以,当我探索。按1,然后把我的球带到特定的位置进行探索。至x 5,y 10,z 15
如何在Unity3d中创建int C#?
答案 0 :(得分:0)
以下是我所制作的代码,在评论中向您解释:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class testscript : MonoBehaviour {
[SerializeField]
List<KeyCode> keys; //array also acceptable here, but i prefer to use Lists
//for line above, this could also be a List<string> because of the other overload of Input.GetKey but this way is best practice
[SerializeField]
Transform transform;
[SerializeField]
List<Vector3> pos;
void Update(){
for (int i = 0; i < keys.Count; i++) { //not foreach because we will need value of i
if (Input.GetKey (keys [i])) { //this will be continuous, you could also use input.GetKeyDown
//*****************
//DO SOMETHING HERE
//*****************
transform.position = pos[i];
Debug.Log ("Yay! A key was pressed!");
}
}
}
}
要回答您的第二个问题,要在C#中int
进行int varname;
,或者在创建时定义它,您可以执行int varname = numval
。