unity2020.1.14f
画面をタップして弾を飛ばす時に使用しています
public class DanganScript : MonoBehaviour {
public GameObject DanganPrefab;
private float power = 100f;
private bool shot;
GameObject Dangan;
void Start( ){
}
void Update( ){
if(Input.GetMouseButtonDown( 0 )){
Dangan = GameObject.Instantiate(DanganPrefab);
ray = camera.main.ScreenPointToRay(Input.mousePosition);
shot = true;
}else{
shot = false;
}
}
void FixedUpdate( ){
if(shot){
if(Dangan != null){
Dangan.GetComponent<Rigidbody>( ).AddForce(ray. direction * power, ForceMode.Impulse);
}
}
}
}
コメント