コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        timeElapsed += Time.deltaTime;
        Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 dir = pos - transform.position;
        //if(facingRight != playerCtrl.facingRight)
        //	Flip ();
        float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

        transform.localRotation = Quaternion.AngleAxis(angle, Vector3.forward);

        //angle = Mathf.Atan2(dir.y, facingRight ? -dir.x : dir.x) * Mathf.Rad2Deg;
        //if(!facingRight)
        //	transform.localRotation = Quaternion.AngleAxis(angle, Vector3.forward);
        if (Input.GetMouseButton(0) && !this.GetComponentInParent <PlayerHealth>().isDead&& timeElapsed >= cooldown)
        {
            //Gun flare effect
            Instantiate(gunFlare, transform.position, transform.rotation);

            //Shoot out a gun
            Rigidbody2D gunBeamInstance = Instantiate(gunBeam, new Vector3(transform.position.x, transform.position.y, 0f), transform.localRotation)
                                          as Rigidbody2D;
            dir.z = 0;
            dir.Normalize();
            gunBeamInstance.velocity = new Vector2(speed * dir.x, speed * dir.y);
            gunBeamInstance.GetComponentInParent <SpriteRenderer>().color = currColor;
            BasicGunBeam currBeam = gunBeamInstance.GetComponentInParent <BasicGunBeam>();
            currBeam.direction  = dir;
            currBeam.speed      = speed;
            currBeam.color      = currColor;
            currBeam.multiplier = multiplier;
            timeElapsed         = 0;
        }
    }
コード例 #2
0
    //TODO: turn this into it's own script called Reflector
    //TODO: Make GunBeam actually be a script called Reflectable which has a direction and a rigidbody2D
    public void reflect(BasicGunBeam beam, Vector2 point, float speed)
    {
        Vector2 reflection = beam.direction - 2 * (Vector2.Dot(beam.direction, currNormal)) * currNormal;

        reflection.Normalize();

        beam.GetComponent <Rigidbody2D>().velocity = new Vector2(speed * reflection.x, speed * reflection.y);
        var angle = Mathf.Atan2(reflection.y, reflection.x) * Mathf.Rad2Deg;

        beam.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        beam.direction          = reflection;
    }
コード例 #3
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "LightObject")
     {
         this.GetComponentInParent <Rigidbody2D>().velocity = new Vector2(0, 0);
         RaycastHit2D cast = Physics2D.Raycast(transform.position, new Vector2(direction.x, direction.y));
         if (cast != null)
         {
             BasicGunBeam beam = other.gameObject.GetComponentInParent <BasicGunBeam>();
             this.GetComponentInParent <Rigidbody2D>().velocity = new Vector2(0, 0);
             other.GetComponentInParent <MirrorFlip>().reflect(this, cast.point, speed);
         }
     }
     else if (other.gameObject.layer == 10)
     {
         other.GetComponentInParent <Attackable>().TakeHit(color, multiplier);
         Destroy(this.gameObject, 0.05f);
     }
     else if (!ignore.Contains(other.gameObject.tag))
     {
         Destroy(this.gameObject);
     }
 }
コード例 #4
0
 public void refract(BasicGunBeam beam, Vector2 point, float speed)
 {
 }