void FireLaser()
    {
        RaycastHit2D hitInfo = Physics2D.Raycast(firePoint.position, -transform.up, laserLength, mask);

        if (hitInfo)
        {
            ShipSubsystems ship = hitInfo.transform.GetComponent <ShipSubsystems>();
            if (ship)
            {
                Debug.Log("Ship hit!");
                ship.DamageOverTime(laserDamage);
            }
            Rigidbody2D hitRB = hitInfo.transform.GetComponent <Rigidbody2D>();
            if (hitRB)
            {
                hitInfo.rigidbody.AddForceAtPosition(strength * -transform.up * Time.deltaTime, hitInfo.point, ForceMode2D.Impulse);
            }
        }

        //draw laser
        laserLine.SetPosition(0, firePoint.position);
        if (hitInfo)
        {
            laserLine.SetPosition(1, hitInfo.point);
        }
        else
        {
            laserLine.SetPosition(1, -transform.up * laserLength + transform.position);
        }
    }
Beispiel #2
0
 // Start is called before the first frame update
 void Start()
 {
     explosionFX     = new List <ParticleSystem>(GetComponentsInChildren <ParticleSystem>());
     explosionSounds = new List <AudioSource>(GetComponentsInChildren <AudioSource>());
     rumbleSound     = GetComponent <AudioSource>();
     shipSubsystems  = GetComponentInParent <ShipSubsystems>();
 }