Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Delay instantiating.

Discussion in 'Scripting' started by Woleth, Jan 25, 2018.

  1. Woleth

    Woleth

    Joined:
    Jan 22, 2018
    Posts:
    6
    When my player shoots a particle it appears with some delay.

    Right after shooting:



    A few moments later:



    Here's the script I'm using to instantiate it:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GunController : MonoBehaviour {
    5.  
    6.     public bool isFiring;
    7.     public BulletController bullet;
    8.     public float bulletSpeed;
    9.     public float timeBetween;
    10.     private float shotCounter;
    11.     public Transform gunPoint;
    12.  
    13.  
    14.     // Use this for initialization
    15.     void Start () {
    16.        
    17.     }
    18.  
    19.     // Update is called once per frame
    20.     void Update () {
    21.         if (isFiring) {
    22.             shotCounter -= Time.deltaTime;
    23.             if (shotCounter <= 0) {
    24.                 shotCounter = timeBetween;
    25.                 BulletController newBullet = Instantiate (bullet, gunPoint.position, gunPoint.rotation) as BulletController;
    26.                 newBullet.speed = bulletSpeed;
    27.             }
    28.         } else {
    29.             shotCounter = 0;
    30.         }
    31.     }
    32. }
     
  2. Errorsatz

    Errorsatz

    Joined:
    Aug 8, 2012
    Posts:
    555
    It may be that the particle takes a moment to become visible. To test that, try instantiating a cube or something instead and see if the delay is still there.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,517
    You can also check the "Prewarm" boolean property on the particle system so it comes out fully-cycled.