Пример #1
0
    // Update is called once per frame
    void Update()
    {
        cannons        = GameObject.Find("OsledShip(Clone)/PirateShip(Clone)/Lookout/Sphere").GetComponent <Lookoutosled>();
        _navMeshAgent  = this.GetComponent <NavMeshAgent>();
        textdeath      = GameObject.Find("OsledShip(Clone)/PirateShip(Clone)/Canvas/death/deathcount").GetComponent <Text>();
        textdeath.text = "" + death;

        if (currentHealth <= 20f && gotoammoo == false && _distanitionG != null)
        {
            gotohealth            = true;
            _navMeshAgent.enabled = true;
            setdis();
        }
        if (_distanitionG == null || currentHealth >= 21f)
        {
            _navMeshAgent.enabled = false;
            gotohealth            = false;
        }
        if (_distanitionB == null || currentHealth >= 21f)
        {
            _navMeshAgent.enabled = false;
            gotoammoo             = false;
        }
        if (cannons.cannons <= 10f && gotohealth == false)
        {
            _navMeshAgent.enabled = true;
            gotoammoo             = true;
            gotoammo();
        }
    }
Пример #2
0
    // Start is called before the first frame update
    void Start()
    {
        rb            = GetComponent <Rigidbody>();
        moved         = chose();
        currentHealth = 100;
        healthBar.SetMaxHealth(maxHealth);
        particles = GetComponentInChildren <ParticleSystem>();
        particles.Stop();
        cannons = GameObject.Find("OsledShip(Clone)/PirateShip(Clone)/Lookout/Sphere").GetComponent <Lookoutosled>();

        textdeath = GameObject.Find("OsledShip(Clone)/PirateShip(Clone)/Canvas/death/deathcount").GetComponent <Text>();

        _distanitionG = GameObject.FindWithTag("Health").transform;
        _distanitionB = GameObject.FindWithTag("Ammo").transform;

        //  transform.rotation = Quaternion.LookRotation(moved);
    }
Пример #3
0
 // on start the ship collects data for the ship rigidbody and  the health and ammo items and sets health to be 100
 void Start()
 {
     items[0]      = GameObject.Find("bottleLarge (1)");
     items[1]      = GameObject.Find("bottle (1)");
     items[2]      = GameObject.Find("bottleLarge");
     items[3]      = GameObject.Find("bottle");
     rb            = GetComponent <Rigidbody>();
     moved         = chose();
     currentHealth = 100;
     healthBar.SetMaxHealth(maxHealth);
     // get partical effect and set it to disabled
     particles = GetComponentInChildren <ParticleSystem>();
     particles.Stop();
     // get how many cannons the ship carries from LookOut script
     cannons = GameObject.Find("OsledShip(Clone)/PirateShip(Clone)/Lookout/Sphere").GetComponent <Lookoutosled>();
     // get the text canvas to input the death and kills gotten
     textdeath = GameObject.Find("OsledShip(Clone)/PirateShip(Clone)/Canvas/death/deathcount").GetComponent <Text>();
     // set a distanation of ammo and health
     _distanitionG = GameObject.FindWithTag("Health").transform;
     _distanitionB = GameObject.FindWithTag("Ammo").transform;
 }
Пример #4
0
    void Update()
    {
        // change visuals depending on the health of the ship to turn on and off sails, and start partical effects
        if (currentHealth <= 80f && currentHealth >= 60f)
        {
            sails[0].SetActive(false);
        }
        if (currentHealth <= 59f && currentHealth >= 40f)
        {
            sails[1].SetActive(false);
        }
        if (currentHealth <= 39f)
        {
            particles.Play();
            sails[2].SetActive(false);
        }

        // get the navmesh component to enable it and disable it if needed
        cannons        = GameObject.Find("OsledShip(Clone)/PirateShip(Clone)/Lookout/Sphere").GetComponent <Lookoutosled>();
        _navMeshAgent  = this.GetComponent <NavMeshAgent>();
        textdeath      = GameObject.Find("OsledShip(Clone)/PirateShip(Clone)/Canvas/death/deathcount").GetComponent <Text>();
        textdeath.text = "" + death;
        // give actions to the AI when the health and ammo and in a certain value then enables nav mesh depending on the situation
        if (currentHealth <= 20f && gotoammoo == false && _distanitionG != null)
        {
            movespeed             = 90;
            gotohealth            = true;
            _navMeshAgent.enabled = true;
            setdis();
        }
        if (_distanitionG == null || currentHealth >= 21f)
        {
            movespeed             = 60;
            _navMeshAgent.enabled = false;
            gotohealth            = false;
        }
        if (_distanitionB == null || currentHealth >= 21f)
        {
            _navMeshAgent.enabled = false;
            gotoammoo             = false;
        }
        if (cannons.cannons <= 10f && gotohealth == false)
        {
            _navMeshAgent.enabled = true;
            gotoammoo             = true;
            gotoammo();
        }
        // start the IEnomunator if a specific bool is set to true or false
        if (escapeandfire == true)
        {
            cannons.__FireFront(4);
        }

        if (ischeck == false)
        {
            StartCoroutine(check());
        }


        // every time the hit ray cast sees an object infront of it like wall or rocks, it will avoid it on a random value , where it choses to go left or right or 180 degrees
        rb.velocity = moved * moveforce;
        if (Physics.Raycast(transform.position, transform.forward, maxdis, hmm))
        {
            int rotLorR = Random.Range(0, 2);

            if (rotLorR == 0)
            {
                transform.Rotate(transform.up * 90);
            }
            if (rotLorR == 1)
            {
                transform.Rotate(transform.up * -90);
            }
            else
            {
                transform.Rotate(transform.up * 180);
            }
        }

        // states of the AI. The AI on defult starts with wandering then in the IEnoumenator, it has a range value to randomly select where to wants to go next and wither if it should rotate or not
        if (iswalk == false)
        {
            StartCoroutine(wandr());
        }
        if (isrotr == true)
        {
            transform.Rotate(transform.up * Time.deltaTime * rotspeed);
        }
        if (isrotl == true)
        {
            transform.Rotate(transform.up * Time.deltaTime * -rotspeed);
        }
        if (iswalk == true)
        {
            transform.position += transform.forward * movespeed * Time.deltaTime;
        }
        // insuring that the health doesnt go above 100
        if (currentHealth > 100)
        {
            currentHealth = 100;
        }
    }