示例#1
0
    private IEnumerator Burst(float _killTime)
    {
        for (int i = 0; i < 3; i++)
        {
            if (m_PaintballPool == null)
            {
                m_PaintballPool = PoolSystem.FindPool("Projectile");
            }
            GameObject burst = m_PaintballPool.m_NextObject;
            burst.transform.position = m_Gun.position;
            burst.transform.rotation = m_Gun.rotation;
            burst.SetActive(true);

            float accuracy = 2.5f;
            CalculateAccuracy(ref burst, accuracy);

            int randomSound = Random.Range(0, fireClips.Length);
            aSource.PlayOneShot(fireClips[randomSound]);

            burst.GetComponent <Rigidbody>().AddForce(burst.transform.forward * m_Force);
            burst.GetComponent <Projectile>().SetOwner(gameObject, (CompareTag(GameManager.TeamEnum.Blue.ToString())) ? GameManager.TeamEnum.Blue : GameManager.TeamEnum.Red);

            yield return(new WaitForSeconds(BURST_FIRE_RATE));
        }
        yield return(null);
    }
示例#2
0
    // Use this for initialization
    void Start()
    {
        trackedObject = viveCntrl.GetComponent <SteamVR_TrackedObject>();
        m_Pool        = PoolSystem.FindPool("Projectile");
        g_Pool        = PoolSystem.FindPool("Grenade");

        m_Stock  = GetComponentInChildren <StockAttributes>();
        m_Barrel = GetComponentInChildren <BarrelAttributes>();

        activeBarrelList.Add(m_BarrelParts[0]);
        activeStockList.Add(m_StockParts[0]);

        m_BarrelIndex = 0;
        m_StockIndex  = 0;

        //manager = GetComponentInChildren<PartManager>();
        Commander = GetComponent <SquadCommand>();

        aSource = GetComponent <AudioSource>();

        isShooting   = false;
        m_Ammunition = 200;

        m_Part         = Part.Barrel;
        m_StateMachine = WeaponState.Weapon;

        reset      = false;
        resetParts = true;

        feedback.enabled = false;
    }
示例#3
0
    void Init()
    {
        pathTime       = animTime = 0;
        rotationDir    = RallyPos = PosMem = storedPos = Vector3.zero;
        nameCheckPoint = GameObject.Find("NameCheck").GetComponent <Collider>();
        rifle          = GetComponentInChildren <FindRifle>().gameObject;
        anim           = GetComponentInChildren <Animator>();
        aSource        = GetComponent <AudioSource>();
        visibleObjects = new List <GameObject>();
        nameReady      = false;
        //Get Components
        m_SkinRenderer            = GetComponentInChildren <SkinnedMeshRenderer>();
        m_HealthManager           = GetComponentInChildren <HealthManager>();
        m_NavAgent                = GetComponent <UnityEngine.AI.NavMeshAgent>();
        m_NavAgent.updateRotation = false;
        m_Camera        = GetComponentInChildren <Camera>();
        m_PaintballPool = PoolSystem.FindPool("Projectile");
        //set the health according to what enemy type it is
        if (isLeader)
        {
            m_HealthManager.SetEntityToMinionLeader();
            transform.localScale = new Vector3(0.75f, 0.75f, 0.75f);
        }
        else
        {
            m_HealthManager.SetEntityToMinion();
        }
        currentState = States.Patrol;

        //set things to false
        SwitchOff();

        //set things to zero
        gunTimer = targetLockTimer = pathTime = 0; //floats

        target = null;

        //precalculations
        m_FireRate = 60.0f / m_FireRate;
        sinTurn    = Mathf.Sin(30.0f);
        cosTurn    = Mathf.Cos(30.0f);
    }
示例#4
0
    public void Fire()
    {
        anim.SetBool("Attack", true);
        anim.SetBool("Walk", false);
        rifle.transform.LookAt(target.position);
        int        randomSound;
        GameObject obj;
        Transform  objTransform;

        if (isLeader)
        {
            StartCoroutine("Burst", KILL_TIME);
        }
        else
        {
            if (m_PaintballPool == null)
            {
                m_PaintballPool = PoolSystem.FindPool("Projectile");
            }
            obj = m_PaintballPool.m_NextObject;
            if (obj == null)
            {
                return;
            }
            objTransform          = obj.transform;
            objTransform.position = m_Gun.position;
            objTransform.rotation = m_Gun.rotation;
            obj.SetActive(true);

            randomSound = Random.Range(0, fireClips.Length);

            if (fireClips[randomSound] != null)
            {
                aSource.PlayOneShot(fireClips[randomSound]);
            }

            obj.GetComponent <Rigidbody>().AddForce(m_Gun.forward * m_Force);
            obj.GetComponent <Projectile>().SetOwner(gameObject, (CompareTag(GameManager.TeamEnum.Blue.ToString())) ? GameManager.TeamEnum.Blue : GameManager.TeamEnum.Red);
        }
    }
示例#5
0
    /// <summary>
    /// Creates a new Pool object and returns it back to you.
    /// </summary>
    /// <param name="resourcePath">The path to the prefab in the resource folder that this pool controls.</param>
    /// <param name="poolSize">The target size that you want the pool to be.</param>
    /// <param name="parent">The parent object that all inactive prefabs will be stored under.</param>
    /// <returns>The newly created pool or an old one if it is already a thing.</returns>
    public static Pool CreatePool(string resourcePath, int poolSize, Transform parent)
    {
      if (string.IsNullOrEmpty(resourcePath))
      {
        throw new System.ArgumentNullException("ResourcePath must have a valid and can't be null");
      }

      Pool pool = PoolBehaviour.instance[resourcePath];


      if (pool != null)
      {
        // We already have a pool created for this item. 
        return pool;
      }

      GameObject prefab = Resources.Load<GameObject>(resourcePath);

      if (prefab == null)
      {
        throw new System.ArgumentNullException("Unable to load prefab at '" + resourcePath + "'. Please make sure this object exists");
      }

      PooledObject pooledObj = prefab.GetComponent<PooledObject>();

      if (pooledObj == null)
      {
        pooledObj = prefab.AddComponent<PooledObject>();
      }

      // Create a new instance of our pool 
      pool = new Pool(resourcePath, parent);

      // Set the target size
      pool.SetPoolSize(poolSize);

      //Return it back to the client. 
      return pool;
    }
示例#6
0
 /// <summary>
 /// Used to add a new Pool instance to the Pool Manager. Pools by default will call this function
 /// when they are created. If the pool already exists in the list it will be ingored. 
 /// </summary>
 /// <param name="pool">The pool you would like to add.</param>
 public static void AddPool(Pool pool)
 {
   if (!PoolBehaviour.instance.pools.Contains(pool))
   {
     PoolBehaviour.instance.pools.Add(pool);
   }
 }