2014-11-06 2 views
0

총 포탑에서 일하고 있습니다. 포탑을 포탑에서 꺼내는 것 외에는 모든 것이 작동합니다. 현재 사용되는 배럴은Unity3d C# 포탑 포탄이 움직이지 않을 것입니다.

입니다. void Start() { firingPointRight = GameObject.FindGameObjectWithTag ("FiringPointRight"). 변형; firingPointLeft = GameObject.FindGameObjectWithTag ("FiringPointLeft"). 변형; }

void Update() { 
    if(Input.GetMouseButton(0)){ 
     count++; 
     if (count >= maxCount) 
     { 
      count = 0; 
      //Debug.Log ("FIRE"); 
      firingPointRight = GameObject.FindGameObjectWithTag ("FiringPointRight").transform; 
      firingPointLeft = GameObject.FindGameObjectWithTag ("FiringPointLeft").transform; 

      // Create cannon muzzle fire effect. 
      GameObject e1 = Instantiate (cannonMuzzleFire) as GameObject; 
      e1.transform.position = firingPointRight.transform.position; 
      e1.transform.rotation = firingPointRight.transform.rotation; 

      Destroy (e1, 0.03f); 

      GameObject e2 = Instantiate (cannonMuzzleFire) as GameObject; 
      e2.transform.position = firingPointLeft.transform.position; 
      e2.transform.rotation = firingPointLeft.transform.rotation; 

      Destroy (e2, 0.03f); 
      //------------------------------------------- 

      //Left cannon. Fire projectile from cannon. 

      //Debug.Log ("Firing Left"); 
      Rigidbody InstantiateedProjectile = Instantiate(cannonAmmo, firingPointLeft.transform.position, firingPointLeft.transform.rotation) as Rigidbody; 
      if (InstantiateedProjectile != null) 
      { 
       print ("Firing projectile"); 
       InstantiateedProjectile.transform.Translate(Vector3.forward * cannonAmmoSpeed * Time.deltaTime); 
      } 

     } 
    } 

답변

2

는 발사체는 자신의 스크립트가 있나요? 인스턴스화 된 발사체에 속도를 설정하는 것처럼 보이지 않습니다.

Translate()는 새로운 위치를 즉시 설정하는 것 외에 이동하는 방식에서 실제로 많이 수행하지 않습니다. 발사체에 Rigidbody 구성 요소가 부착 된 경우 강체의 속도를 직접 설정할 수 있습니다. 그래서 같이

: 그것은 단지 계산이 모든 프레임을 실행에 포함 할 필요가 있기 때문에

InstantiateedProjectile.velocity = Vector3.forward * cannonAmmoSpeed; 

Time.deltaTime는, 여기에 사용되지 않습니다. 보조 노트로


, 당신은 당신의 플레어 효과를 재사용하는 대신 새로운마다 총 산란을 고려해 볼 수 있습니다. 효과를 보이지 않게하고 샷 사이에서 효과를 재설정 할 수 있습니다. 그러면 성능이 향상됩니다.

+0

감사합니다. 검사관의 강체에 대해 Is Kinematic 체크 박스의 선택을 취소하여 작동 시켰습니다. 나는 발사체 속도도 사용했다. – jadkins4

관련 문제