Exemplo n.º 1
0
 public virtual void Awake()
 {
     Animator     = GetComponent <Animator>();
     _colliders   = transform.root.GetComponentsInChildren <Collider2D>();
     _weaponAudio = GetComponentInParent <F3DWeaponAudio>();
     _fireTimer   = _fireRate;
 }
Exemplo n.º 2
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        // Send damage and spawn hit effects


        var contacts       = new ContactPoint2D[2];
        var contactsLength = other.GetContacts(contacts);

        if (contactsLength > 0)
        {
            var contact = other.contacts[0];

            DealDamage(Source, DamageType, DamageAmount, WeaponType, contact.collider.transform, Hit, HitLifeTime, contact.point, contact.normal);

            // Play hit sound
            F3DWeaponAudio.OnProjectileImpact(Audio, AudioInfo);

            // Disable Physics if we have any
            if (_rBody != null && _collider != null)
            {
                _rBody.isKinematic = true;
                _collider.enabled  = false;

                _rBody.simulated = false;
            }

            // Hide the sprite
            if (PostHitHide)
            {
                _pSystem.Stop(true);
                _pSystem.Clear(true);
            }

            // Despawn self
            F3DSpawner.Despawn(transform, DelayDespawn);
        }
    }
Exemplo n.º 3
0
    protected void SpawnProjectile(Transform projectilePrefab)
    {
        // Direction
        _dir = Mathf.Sign(FXSocket.parent.lossyScale.x);

        // Run close distance check from the bone pivot to the FXSocket twice long

        //
        Debug.DrawLine(FXSocket.position - FXSocket.right * _dir,
                       FXSocket.position + FXSocket.right * 2 * _dir, Color.red, 0.5f);

        //
        var closeCheckHit = Physics2D.LinecastAll(FXSocket.position - FXSocket.right * _dir,
                                                  FXSocket.position + FXSocket.right * ProjectileCloseRange * _dir, ProjectileHitLayerMask);

        // Close range hit - Spawn the impact and play hit sound without spawning the projectile
        if (closeCheckHit != null && closeCheckHit.Length > 0)
        {
            var projObject = projectilePrefab.GetComponent <F3DGenericProjectile>();

            // Ignore own colliders
            for (var i = 0; i < closeCheckHit.Length; i++)
            {
                var selfHit = false;
                for (var j = 0; j < _colliders.Length; j++)
                {
                    if (closeCheckHit[i].collider == _colliders[j])
                    {
                        selfHit = true;
                        break;
                    }
                }
                if (selfHit)
                {
                    continue;
                }

                F3DGenericProjectile.DealDamage(transform.root.gameObject, DamageType, DamageAmount, Type, closeCheckHit[i].transform, projObject.Hit,
                                                projObject.HitLifeTime,
                                                closeCheckHit[i].point, closeCheckHit[i].normal);
                // Play close impact through the attached soundSource
                F3DWeaponAudio.OnProjectileImpact(_weaponAudio.ProjectileHitClose, AudioInfo);
                return;
            }
        }

        // Keep the initial position, rotaion of the FXSocket so the projectile is launched in the correct _dir
        // Random Offset

        // Position
        var position = FXSocket.position + FXSocket.right * ProjectileOffset.x * _dir;

        position.z = 0;

        // Rotation
        var rotation = FXSocket.rotation;

        if (_dir < 0)
        {
            rotation *= Quaternion.Euler(0, 0, 180);
        }
        rotation *= Quaternion.Euler(0, 0, Random.Range(ProjectileRotation.x, ProjectileRotation.y));

        // Spawn Delayed
        StartCoroutine(SpawnProjectileDelayed(projectilePrefab, position, rotation));
    }
Exemplo n.º 4
0
    private void SetLinePoints()
    {
        if (_alreadyHit)
        {
            _lineRenderer.startColor = _lerpColor;
            _lineRenderer.endColor   = _lerpColor;
        }

        if (_lineRenderer == null)
        {
            return;
        }
        if (_lineMaterial == null)
        {
            return;
        }

        // Set the initial line point
        _linePoints[0]   = transform.position;
        _linePoints[0].z = 0;

        // Direction
        var direction = Mathf.Sign(transform.parent.lossyScale.x);

        // Linecast
        var farPoint = transform.position + transform.right * MaxLength * direction;
        var lineHit  = Physics2D.Linecast(transform.position, farPoint, LineCastMask);

        if (lineHit.collider != null)
        {
            // Set end point
            _linePoints[1]   = lineHit.point;
            _linePoints[1].z = 0;

//            // Align the midpoint
//            _linePoints[1] = transform.position +
//                             (new Vector3(lineHit.point.x, lineHit.point.y, 0) - transform.position) * 0.5f;
//            _linePoints[1].z = 0;

            // Damage and Hit Effects
            if (Hit && !_alreadyHit)
            {
                DealDamage(transform.root.gameObject, DamageType, DamageAmount, WeaponType, lineHit.transform, Hit, HitLifeTime, lineHit.point, lineHit.normal);
                _alreadyHit = true;

                // Shift the AudioSource attached to this pulse to the lineEnd position
                if (Audio.transform != this.transform)
                {
                    Audio.transform.position = lineHit.point;
                }

                // Play hit sound
                F3DWeaponAudio.OnProjectileImpact(Audio, AudioInfo);
            }
        }
        else // Line hits nothing
        {
            _alreadyHit = true;

            // Midpoint
            _linePoints[1]   = farPoint;// + (farPoint - transform.position) * 0.3f;
            _linePoints[1].z = 0;

            //            // Endpoint offset along to fade out smoothly
            //            _linePoints[2] = farPoint;// + (farPoint - transform.position) * 0.5f;
            //            _linePoints[2].z = 0;

            _lineRenderer.startColor = _lerpColor;
            _lineRenderer.endColor   = Color.clear;
        }
        _lineRenderer.SetPositions(_linePoints);

        // Kepp tiling over distance
        var texScale = _lineMaterial.mainTextureScale;

        texScale.x = Tiling * Vector3.Distance(_linePoints[0], _linePoints[1]);
        _lineMaterial.mainTextureScale = texScale;

        // Animate Offset
        var texOffset = _lineMaterial.mainTextureOffset;

        texOffset.x -= Time.deltaTime * 12;
        _lineMaterial.mainTextureOffset = texOffset;

        _lerpColor = Color.Lerp(_lerpColor, Color.clear, Time.deltaTime * FadeRate);
    }