2016-11-05 20 views
-3

hi 私はミニゴルフゲームを始めたい場所がどこにあるのか、ゲームを作りたいと思っています... だから私はexpl。 1を押し、私のボールをexplのために特定のポジションに持って行きます。 〜x 5、y 10、z 15キーボードのプレスでオブジェクトの位置を設定する方法は?

Unity3dでint C#を作成するにはどうすればよいですか?

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

そして、あなたはint varname;を行うかを定義するためにC#でintを作るために、あなたの2番目の質問に答えるために:ここで

+0

あなたのコードはどこですか? –

+0

これはあなたが尋ねる質問のタイプではありませんstackoverflow – Bijan

+0

まず、このためのコードを記述してください。コーディング中に立ち往生した場合は、ここで質問してその特定の問題に関連するヘルプを得ることができます。 –

答えて

0

は私が作ったコードで、道に沿ってあなたに説明してコメントしています作成時にint varname = numvalを実行できます。

関連する問題