ワープポイントを作ろう:transform.position

オブジェクトをワープさせる
using UnityEngine;
using System.Collections;
public class WarpPoint : MonoBehaviour {
void OnTriggerEnter(Collider other){
// (考え方)触れた瞬間にボールに新しい位置情報をセットする。
// 「0.5f」のように「小数」を使用する場合には必ず「f」を書くこと(ポイント)
// 「f」は「float(浮動小数点)」の略
other.gameObject.transform.position = new Vector3(-3, 0.5f, -3);
}
}







複数のワープポイントに対応させる
using UnityEngine;
using System.Collections;
public class WarpPoint : MonoBehaviour {
// ★改良
public Vector3 pos;
void OnTriggerEnter(Collider other){
// ★改良
other.gameObject.transform.position = new Vector3(pos.x, pos.y, pos.z);
}
}


【旧版】BallGame(全25回)
他のコースを見る
オブジェクトをワープさせる
using UnityEngine;
using System.Collections;
public class WarpPoint : MonoBehaviour {
void OnTriggerEnter(Collider other){
// (考え方)触れた瞬間にボールに新しい位置情報をセットする。
// 「0.5f」のように「小数」を使用する場合には必ず「f」を書くこと(ポイント)
// 「f」は「float(浮動小数点)」の略
other.gameObject.transform.position = new Vector3(-3, 0.5f, -3);
}
}







複数のワープポイントに対応させる
using UnityEngine;
using System.Collections;
public class WarpPoint : MonoBehaviour {
// ★改良
public Vector3 pos;
void OnTriggerEnter(Collider other){
// ★改良
other.gameObject.transform.position = new Vector3(pos.x, pos.y, pos.z);
}
}


ワープポイントを作ろう:transform.position