2017-03-13 5 views
-6

私はどこに移動したいのですか?このような例,,C#私が欲しい場所に移動する方法

else if (this.inputLine.StartsWith("/teleport")) 


............................... transform.position = new Vector3(71,79,-79); 




how to put 71,79,-79 after command? so like this, 
    else if (this.inputLine.StartsWith("/teleport 71 79 -79")); 

use (Convert.ToInt32(this.inputLine.Remove(0, 3))???? how? please help me 
+0

文字列を解析する方法を尋ねていますか? [String.Splitメソッド](https://msdn.microsoft.com/en-us/library/system.string.split(v = vs.110).aspx)または[Regex](https://msdn.microsoft –

+1

これを達成するのに役立つ方法がある 'DR SPOCK 'を見てみましょう。 – MethodMan

+0

ハリー・ポッターの1人映画はあなたに秘密を教えてくれます.... – Trey

答えて

1

のためにあなたは、あなたの質問に非常に多くの情報を与えることはありませんが、あなたのコードから私は、次のと仮定しています:

  1. をあなたが使用しているUnity3D
  2. をユーザーがコマンドを入力できるテキスト入力コントロールがあります。
  3. ブロックif-elseは、すべての可能なコマンドを繰り返し実行し、必要な処置を完了します。
  4. この場合、「/ teleport」を入力した後にユーザーが入力した値に一致するゲーム内の場所に移動したいと考えています。

文字列を入力して短縮し、残りの文字列を' 'セパレータを使用して解析することをお勧めします。 これは、ベクトル値を持つ文字列配列を返します。 次に、この配列の各文字列をintに変換し、これらのintを新しい場所の決定に使用する変数に割り当てることができます。代わりに、int型のサブストリングを作成することの代替として

// Input: /teleport 30 146 18 

else if (this.inputLine.StartsWith("/teleport") 
{ 
    // Gets what the user typed. 
    string input = inputLine.Text; 
    // Removes the "/teleport" part of string. 
    string vectorString = input.Substring(8); 
    // Splits the remaining string into an array of values using ' ' delimiter. 
    string[] va = vectorString.Split(' '); 
    // Converts values from string to int. 
    int x = Convert.ToInt32(va[0]); 
    int y = Convert.ToInt32(va[1]); 
    int z = Convert.ToInt33(va[2]); 
    // Changes the position using these ints. 
    transform.position = new Vector3(x, y, z); 
} 

、あなたが文字列を分割した後、素子2,3を割り当て、配列の最初の要素の使用を避けることができ、及び4:例えば

+0

ありがとう、私はそれを得る:D –

+0

私を助けることができますか? http://stackoverflow.com/questions/43394759/how-to-teleport-to-another-player-with-id –

関連する問題