Ejemplo n.º 1
0
    public string Fire()
    {
        if (!Ability.CanRun(energyAgent.EnergyPool))
        {
            return(null);
        }

        bool hitSomething = false;

        energyAgent.UseAbility(Ability);
        //Create a vector at the center of our camera's near clip plane.
        Vector3 rayOrigin = gameObject.transform.position;

        //Draw a debug line which will show where our ray will eventually be
        Debug.DrawRay(rayOrigin, transform.forward * Ability.weaponRange, Color.green);

        //Declare a raycast hit to store information about what our raycast has hit.
        RaycastHit hit;

        //Set the start position for our visual effect for our laser to the position of gunEnd
        laserLine.SetPosition(0, transform.position);

        //Check if our raycast has hit anything
        if (Physics.Raycast(rayOrigin, transform.forward, out hit, Ability.weaponRange))
        {
            hitSomething = true;
            //Set the end position for our laser line
            laserLine.SetPosition(1, hit.point);

            //Get a reference to a health script attached to the collider we hit
            HealthAgent health = hit.collider.GetComponent <HealthAgent>();

            //If there was a health script attached
            if (health != null)
            {
                //Call the damage function of that script, passing in our gunDamage variable
                health.Damage(Ability.gunDamage * Time.deltaTime);
            }

            //Check if the object we hit has a rigidbody attached
            if (hit.rigidbody != null)
            {
                //Add force to the rigidbody we hit, in the direction it was hit from
                hit.rigidbody.AddForce(-hit.normal * Ability.hitForce);
            }
        }
        else
        {
            //if we did not hit anything, set the end of the line to a position directly away from
            laserLine.SetPosition(1, transform.forward * Ability.weaponRange);
        }

        if (LaserActive != null)
        {
            StopCoroutine(LaserActive);
        }

        LaserActive = StartCoroutine(FireEnable());
        return(hitSomething ? hit.collider.gameObject.tag : null);
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    public override void InitializeAgent()
    {
        base.InitializeAgent();
        agentRb     = GetComponent <Rigidbody>();
        rayPer      = GetComponent <RayPerception3D>();
        HealthAgent = GetComponent <HealthAgent>();

        FloatVariable health = ScriptableObject.CreateInstance <FloatVariable>();

        health.InitialValue = InitialHealth;
        health.RuntimeValue = InitialHealth;
        HealthAgent.Health  = health;

        Academy = GameObject.FindObjectOfType <CibotAcademy>();
    }
Ejemplo n.º 3
0
    // Start is called before the first frame update
    public override void InitializeAgent()
    {
        base.InitializeAgent();
        agentRb        = GetComponent <Rigidbody>();
        rayPer         = GetComponent <RayPerception3D>();
        HealthAgent    = GetComponent <HealthAgent>();
        EnergyAgent    = GetComponent <EnergyAgent>();
        RaycastShooter = GetComponent <RaycastShooter>();

        PlayerHealthAgent = Player.GetComponent <HealthAgent>();

        FloatVariable health = ScriptableObject.CreateInstance <FloatVariable>();

        health.InitialValue = InitialHealth;
        health.RuntimeValue = InitialHealth;
        HealthAgent.Health  = health;

        FloatVariable energy = ScriptableObject.CreateInstance <FloatVariable>();

        energy.InitialValue    = InitialEnergy;
        energy.RuntimeValue    = InitialEnergy;
        EnergyAgent.EnergyPool = energy;
    }
Ejemplo n.º 4
0
 void Start()
 {
     HealthAgent = GetComponent <HealthAgent>();
     EnergyAgent = GetComponent <EnergyAgent>();
 }