if(Input.GetButtonUp("Fire1"))
{
Debug.Log("shoot");
Rigidbody instance = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;
instance.AddForce (shooter * power);
}
error CS0039: Cannot convert type `UnityEngine.GameObject' to `UnityEngine.Rigidbody' via a built-in conversion
Rigidbody 선언이 에러난다.
그러면 다른 방법 ->
if(Input.GetButtonUp("Fire1"))
{
Debug.Log("shoot");
GameObject instance = Instantiate(bullet, transform.position, transform.rotation);
instance.GetComponent<Rigidbody> ().AddForce (shooter * power);
}
다르게 접근하자 By GetComponent
'DEV > Unity' 카테고리의 다른 글
Unity 3D: 레이케스팅 Raycasting (0) | 2017.04.20 |
---|---|
3D Unity 과제 (0) | 2017.04.20 |
Prefab Instantiate in Canvas / doesn't show in my Canvas (0) | 2017.03.14 |
public animation 선언 했는데, 드래그가 안됨, 씬에서 찾을 수 없다고 함 (0) | 2017.03.05 |
Unity Animation Stop은 되지만, Play 가 다시 되지 않을때 (1) | 2017.03.05 |