Search Unity

Particle dont dissapear and leave trail behind ship :(

Discussion in 'Scripting' started by Zaboleq, Nov 28, 2012.

  1. Zaboleq

    Zaboleq

    Joined:
    Nov 1, 2012
    Posts:
    21
    I have big problem with my particles :/

    http://imgur.com/o34Vs

    When I move my ship with "wsad", particle leave trail behind the ship - they should disapear I think but they dont :/. Could anyone can help me with this? Without destroying particles, everything sucks...

    Here is my whole script :
    I got thir error and meyby this is the problem:
    Assets/Moje_Skrypty/LookAtMouse.cs(73,28): warning CS0219: The variable `showEngine' is assigned but its value is never used

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LookAtMouse : MonoBehaviour
    5.    
    6. {
    7.  
    8.     // speed is the rate at which the object will rotate
    9.     public float speed;
    10.     public float shipSpeed;
    11.     public GameObject engine;
    12.     public GameObject enginePrefab;
    13.     public bool engineStarted;
    14.     public GameObject  showEngine;
    15.    
    16.    
    17.  
    18.     void FixedUpdate ()
    19.     {
    20.        
    21.         Plane playerPlane = new Plane(Vector3.up, transform.position);
    22.  
    23.        
    24.         Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    25.  
    26.        
    27.         float hitdist = 0.0f;
    28.        
    29.         if (playerPlane.Raycast (ray, out hitdist))
    30.         {
    31.            
    32.             Vector3 targetPoint = ray.GetPoint(hitdist);
    33.        
    34.        
    35.        
    36.        
    37.            
    38.             Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
    39.  
    40.            
    41.             transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.time);
    42.            
    43.            
    44.             if (Input.GetKey("w") || Input.GetKey("s") || Input.GetKey("a") || Input.GetKey("d"))
    45.             //if(silnikiodpalone == false)
    46.             {
    47.                 startEngine(); 
    48.             }
    49.             else
    50.                
    51.             {
    52.                 stopEngine();
    53.                
    54.             }
    55.         float movingShipAxisX = Input.GetAxis("Horizontal") * shipSpeed * Time.fixedDeltaTime;
    56.         transform.Translate(Vector3.right * movingShipAxisX, Space.World);
    57.        
    58.        
    59.         float movingShipAxisY = Input.GetAxis("Vertical") * shipSpeed * Time.fixedDeltaTime;
    60.         transform.Translate(Vector3.forward * movingShipAxisY, Space.World);
    61.         }
    62.        
    63.        
    64.        
    65.        
    66.        
    67.     }
    68.    
    69.     void startEngine()
    70.     {
    71.         //if(engineStarted == false)
    72.         {
    73.         GameObject showEngine = (GameObject)Instantiate(enginePrefab, engine.transform.position, engine.transform.rotation);
    74.         }
    75.         //engineStarted = true;
    76.     }
    77.    
    78.     void stopEngine()
    79.     {
    80.         Destroy(showEngine);
    81.        
    82.     }
    83.    
    84.    
    85. }
     
  2. Kwaung

    Kwaung

    Joined:
    Sep 19, 2012
    Posts:
    3
    Try
    Code (csharp):
    1.  
    2. showEngine = (GameObject)Instantiate(enginePrefab, engine.transform.position, engine.transform.rotation);
    3.