// Update is called once per frame
    void Update()
    {
        if (shipInputHandler != null)
        {
            isFiring = shipInputHandler.IsFiring();
        }

        if (isFiring)
        {
            if (Physics.SphereCast(transform.position, 3, transform.forward, out RaycastHit raycastHit, weaponMaxDistance))
            {
                hitPosition = raycastHit.point;

                laserHitParticleSystem.transform.position = hitPosition + transform.forward;

                laserParticleSystemEmissionModule.rateOverTime = 10;

                HPHandler hpHandler = raycastHit.transform.root.GetComponent <HPHandler>();

                if (hpHandler != null)
                {
                    hpHandler.OnHit(weaponDamage);
                }
            }
            else
            {
                hitPosition = transform.position + transform.forward * weaponMaxDistance;
                laserParticleSystemEmissionModule.rateOverTime = 0;
            }

            //Render LAZERS
            lineRenderer.enabled = true;
            lineRenderer.SetPosition(0, transform.position);
            lineRenderer.SetPosition(1, hitPosition);
        }
Example #2
0
    void Awake()
    {
        GameObject player = GameObject.FindGameObjectWithTag("Player");

        shipFuelHandler  = player.GetComponent <ShipFuelHandler>();
        hpHandler        = player.GetComponent <HPHandler>();
        shipInputHandler = player.GetComponent <ShipInputHandler>();
    }
Example #3
0
        internal void FixedUpdate()
        {
            if (activeMode == MovementMode.walking && agent.remainingDistance < 10f && agent.remainingDistance > 8f)
            {
                blockMoves = 120;
            }

            if (activeMode == MovementMode.walking && agent.remainingDistance < 5f && blockMoves-- <= 0)
            {
                agent.destination = this.transform.position;
                this.activeMode   = MovementMode.idle;
                clearCache();
                moveRand();
            }

            counter++;
            //search for new enemy
            if (counter % 10 == 0 && activeEnemy == null)
            {
                activeEnemy = findClosestEnemy();
                if (activeEnemy != null)
                {
                    enemyHP       = activeEnemy.GetComponent <HPHandler>();
                    enemyCollider = activeEnemy.GetComponent <Collider>();
                }
            }

            if (activeEnemy == null || lockState)
            {
                if (activeEnemy == null && activeMode == MovementMode.idle)
                {
                    useTargetCache();
                }
                return;
            }

            cacheMoveTarget();

            //update state
            var enemyPoint = enemyCollider.ClosestPoint(this.transform.position);
            var dist       = Vector3.Distance(this.transform.position, enemyPoint);

            if (dist > scanRange)
            {
                //too far away
                activeEnemy = null;
                if (activeMode != MovementMode.walking)
                {
                    activeMode = MovementMode.idle;
                }
                return;
            }
            else if (dist > maxRange)
            {
                activeMode = MovementMode.approaching;
            }
            else if (dist > minRange)
            {
                //in range, betweent min and max range
                var optimalDist = maxRange * optimalRange;
                if (dist > optimalDist + 1)
                {
                    activeMode = MovementMode.inRange_closing;
                }
                else if (dist > optimalDist - 1)
                {
                    activeMode = MovementMode.inRange_staying;
                }
                else
                {
                    activeMode = MovementMode.inRange_opening;
                }
            }
            else if (dist <= minRange)
            {
                activeMode = MovementMode.tooClose;
            }

            updatePos(activeEnemy, activeMode, enemyPoint);

            //now let the subclass do with the state what it wants
        }
 void Awake()
 {
     hpHandler = GetComponent <HPHandler>();
 }
Example #5
0
 public void Start()
 {
     ownResource.Add(new ressourceStack(getHP().getInitialHP(), getHP().type));
     hp  = this.GetComponent <HPHandler>();
     inv = this.GetComponent <inventory>();
 }