/// <summary> /// Method for spawning the rockets. /// </summary> /// <param name="spawn">The actual spawn Transform(either left or right bikini side).</param> /// <param name="range">Actual range parameter.</param> /// <returns></returns> public void spawnRocket(Transform spawn, float range) { // 0.75f*gameObject.transform.forward because to avoid colliding with the character //GameObject spawnedRocket = ObjectsPool.Spawn(rocket, spawn.position + 0.75f * gameObject.transform.forward, Quaternion.LookRotation(spawn.forward)); GameObject spawnedRocket = (GameObject)Instantiate(rocket, spawn.position + 0.75f * gameObject.transform.forward, Quaternion.LookRotation(spawn.forward)); // Gets the particle system from the parent game object ParticleSystem particleSystem = spawnedRocket.GetComponentInChildren <ParticleSystem>() as ParticleSystem; // The emission of the particle system is disabled because of the default rotation particleSystem.enableEmission = false; // Set the looking direction of the rocket to the target Vector3 direction = gameObject.transform.forward * range; /* * direction = Quaternion.Euler(0, -angularOffset + addRotation, 0) * direction; * direction *= (mulRange + addRange); */ // Set the target position of the rocket Vector3 targetPosition = gameObject.transform.position + direction; // Quick and dirty! Set the destination to a negative value, so it muast not be destroyed and the rocket trail is able to smoothly disappear targetPosition.y = -50f; // Get the rocketbehaviour component... RocketBehaviour rocketBehaviour = spawnedRocket.GetComponent <RocketBehaviour>(); // And set the ownerscript (for datamining) rocketBehaviour.OwnerScript = this.OwnerScript; // Scale the size of the rocket to one fith of the original size spawnedRocket.gameObject.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); // Call Launch from the attached rocketbehaviour script rocketBehaviour.Launch(targetPosition); // The rocket looks into the right direction so we can enable the emission of the particle system particleSystem.enableEmission = true; }