Ejemplo n.º 1
0
    public void defaultShoot(bool isEnemy)
    {
        var shotTransform = Instantiate(shotPrefab) as Transform;

        shotTransform.position = transform.position;
        PlayerBulletScript shot = shotTransform.gameObject.GetComponent <PlayerBulletScript>();

        if (shot != null)
        {
            shot.isEnemyShot = isEnemy;
        }

        PulpyScript move = shotTransform.gameObject.GetComponent <PulpyScript>();

        if (move != null)
        {
            if (shootRight)
            {
                move.direction = this.transform.right;
            }
            else
            {
                move.direction = this.transform.right * -1;
            }
        }
    }
Ejemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     if (timerShootCooldown >= shootCooldown)
     {
         timerShootCooldown = 0;
         float      _Y     = Random.Range(-deltaY, deltaY);
         GameObject newBul = Instantiate(Bullet, new Vector3(transform.position.x, _Y, 3),
                                         new Quaternion());
         PulpyScript mov = newBul.GetComponent <PulpyScript>();
         mov.direction.y = -1 / Mathf.Sqrt(2);
         mov.direction.x = -1;
         mov.speed.x     = 5;
         mov.speed.y     = 5;
         newBul          = Instantiate(Bullet, new Vector3(transform.position.x, _Y, 3),
                                       new Quaternion());
         mov             = newBul.GetComponent <PulpyScript>();
         mov.direction.y = 0;
         mov.direction.x = -1;
         mov.speed.x     = 5;
         mov.speed.y     = 5;
         newBul          = Instantiate(Bullet, new Vector3(transform.position.x, _Y, 3),
                                       new Quaternion());
         mov             = newBul.GetComponent <PulpyScript>();
         mov.direction.y = 1 / Mathf.Sqrt(2);
         mov.direction.x = -1;
         mov.speed.x     = 5;
         mov.speed.y     = 5;
     }
     else
     {
         timerShootCooldown += Time.deltaTime;
     }
 }
Ejemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (currShoot >= shootCooldown)
     {
         Vector3 currPosition;
         currPosition = Player.transform.position;
         if (GameObject.FindGameObjectWithTag("Player") != null)
         {
             GameObject newBul = Instantiate(Bullet, new Vector3(transform.position.x, transform.position.y, 3),
                                             new Quaternion());
             PulpyScript mov = newBul.GetComponent <PulpyScript>();
             currPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
             Vector3 vec = currPosition - transform.position;
             vec.Normalize();
             mov.direction.x = vec.x;
             mov.direction.y = vec.y;
             mov.speed.x     = 5;
             mov.speed.y     = 5;
             currShoot       = 0;
         }
     }
     else
     {
         currShoot += Time.deltaTime;
     }
 }
Ejemplo n.º 4
0
    public void autoShoot(bool isEnemy)
    {
        Transform shotTransform = Instantiate(shotPrefab);

        GameObject[] enem   = GameObject.FindGameObjectsWithTag("Enemy");
        GameObject[] bosses = GameObject.FindGameObjectsWithTag("Boss");

        float      minDist = Mathf.Infinity;
        GameObject minObj  = new GameObject("tmp");
        Vector3    currPos = new Vector3();

        if (GameObject.FindGameObjectsWithTag("Player") != null)
        {
            currPos = GameObject.FindGameObjectWithTag("Player").transform.position;
        }
        if (enem != null || (bosses != null))
        {
            foreach (GameObject g in enem)
            {
                if (Vector3.Distance(currPos, g.transform.position) < minDist)
                {
                    if (currPos.x < g.transform.position.x)
                    {
                        minDist = Vector3.Distance(currPos, g.transform.position);
                        minObj  = g;
                    }
                }
            }
            foreach (GameObject g in bosses)
            {
                if (Vector3.Distance(currPos, g.transform.position) < minDist)
                {
                    minDist = Vector3.Distance(currPos, g.transform.position);
                    minObj  = g;
                }
            }
            Vector3 vec = new Vector3(1, 0, 0);
            if (minObj.transform.position.x
                > currPos.x)
            {
                vec = minObj.transform.position - currPos;
                vec.Normalize();
            }
            shotTransform.position = currPos;
            float angle = Mathf.Atan2(vec.y, vec.x) * Mathf.Rad2Deg;
            shotTransform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
            PulpyScript mov = shotTransform.GetComponent <PulpyScript>();
            mov.direction.x = vec.x;
            mov.direction.y = vec.y;
            mov.speed.x     = 20;
            mov.speed.y     = 20;
            GameObject onDel = GameObject.Find("tmp");
            Destroy(onDel);
        }
    }
Ejemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     currShoot += Time.deltaTime;
     if (currShoot >= shootCooldown)
     {
         if (isPositiveChange)
         {
             if (currAngle == maxAngle)
             {
                 isPositiveChange = false;
             }
             else
             {
                 GameObject newBul = Instantiate(Bullet, new Vector3(transform.position.x, transform.position.y, 3),
                                                 new Quaternion());
                 PulpyScript mov = newBul.GetComponent <PulpyScript>();
                 mov.direction.x = -1;
                 mov.direction.y = currAngle;
                 mov.speed.x     = 5;
                 mov.speed.y     = 5;
                 currAngle      += deltaAngle;
                 currShoot       = 0;
             }
         }
         else
         {
             if (currAngle == -maxAngle)
             {
                 isPositiveChange = true;
             }
             else
             {
                 GameObject newBul = Instantiate(Bullet, new Vector3(transform.position.x, transform.position.y, 3),
                                                 new Quaternion());
                 PulpyScript mov = newBul.GetComponent <PulpyScript>();
                 mov.direction.x = -1;
                 mov.direction.y = currAngle;
                 mov.speed.x     = 5;
                 mov.speed.y     = 5;
                 currAngle      -= deltaAngle;
                 currShoot       = 0;
             }
         }
     }
 }
Ejemplo n.º 6
0
    public void trippleDeploy(Transform pos)
    {
        Transform shotTransformUp   = Instantiate(shotPrefab);
        Transform shotTransformDown = Instantiate(shotPrefab);

        shotTransformDown.transform.position = transform.position;
        shotTransformUp.transform.position   = transform.position;
        shotTransformUp.rotation             = Quaternion.Euler(new Vector3(0, 0, 45 / 2));
        shotTransformDown.rotation           = Quaternion.Euler(new Vector3(0, 0, -45 / 2));
        PulpyScript movUp   = shotTransformUp.GetComponent <PulpyScript>();
        PulpyScript movDown = shotTransformDown.GetComponent <PulpyScript>();

        movUp.direction.x   = 1 / Mathf.Sqrt(2);
        movUp.direction.y   = 1 / Mathf.Sqrt(2);
        movUp.speed.y       = movUp.speed.x / 4;
        movDown.direction.x = 1 / Mathf.Sqrt(2);
        movDown.direction.y = 1 / -Mathf.Sqrt(2);
        movDown.speed.y     = movDown.speed.x / 4;
    }