Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Awake()
    {
        agent = GetComponent <NavMeshAgent>();
        cam   = Camera.main;

        GameObject           obj        = GameObject.FindWithTag("Finish");
        DamageableGameObject dgo        = obj.GetComponent <DamageableGameObject>();
        GameObject           projectile = Instantiate(prefab, transform.position, Quaternion.identity) as GameObject;
        ProjectileController controller = projectile.GetComponent <ProjectileController>();

        controller.Init(dgo, 20);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Fire the ship's weapons.
    /// </summary>
    public void Shoot()
    {
        //get a reference to the newly created projectile object
        GameObject projectileGO = Instantiate(projectilePrefab, transform.position, transform.rotation);
        //projectile.Awake(), .OnEnable(), and .Start() happen all before program gets here.

        //get a reference to the component that exists on the newly created GO
        ProjectileController projectileController = projectileGO.GetComponent <ProjectileController>();

        //set starting values, like speed and owner
        projectileController.Init(this.gameObject.tag, projectileMoveSpeed, projectileClip);
    }
Ejemplo n.º 3
0
 private void CreateProjectiles(GameObject template)
 {
     for (int i = 0; i < oneShotAmmoNeed; i++)
     {
         GameObject projectile = pool.GetProjectileAndActivate(ammoType);
         if (projectile != null)
         {
             projectile.transform.position = this.gameObject.transform.position;
             ProjectileController pc = projectile.GetComponent <ProjectileController>();
             pc.Init(ammoType, force);
         }
     }
 }
Ejemplo n.º 4
0
    public void FireProjectile()
    {
        Vector3    relativePos   = target.transform.position - transform.position;
        GameObject newProjectile = Instantiate(
            Projectile, Nozzle.transform.position, Quaternion.LookRotation(relativePos, Vector3.up)
            );

        // add projectile modifire to the new projectile
        ProjectileController controller = newProjectile.GetComponent <ProjectileController>();

        controller.Init(this.projectileModifier);

        nextFire = Time.time + fireCooldownInSeconds * controller.GetCooldownMultiplier();
    }