Inheritance: MonoBehaviour
 // Start is called before the first frame update
 void Start()
 {
     //gain aceess to the amount of health the player has for decision making
     player = FindObjectOfType <playerHealth>();
     //get hold of score manager for svaing score
     scoreManager = FindObjectOfType <scoreManager>();
 }
Ejemplo n.º 2
0
 private void Awake()
 {
     playerHealth   = GetComponent <playerHealth>();
     playerAnimator = GetComponent <Animator>();
     playerSource   = GetComponents <AudioSource>();
     fadeInOut      = GameObject.Find("FadeInOutSprite").GetComponent <SceneFadeOut>();
 }
Ejemplo n.º 3
0
 // *** This script will be on gameobject which has Animator i.e. on actual model. Genererally we have scripts on parents so that all children move together
 // but here we need ATTACK animations to set some values in this script. So we need to place this script on the model
 void Start()
 {
     //zombieNavmeshAgent = this.gameObject.GetComponent<NavMeshAgent>();
     // zombieNavmeshAgent is on the parent object
     zombieNavmeshAgent.SetDestination(houseAsATargetTransform.position);
     pHealthScript = Object.FindObjectOfType <playerHealth>();
 }
Ejemplo n.º 4
0
	// Use this for initialization
	void Start () {
		theSpawnDoor = GameObject.Find ("winningConditions").GetComponent <spawnDoor> ();

		Time.timeScale = 1;
		thePlayerScore = GameObject.Find("_GM").GetComponent<scoreController> ();
		thePlayerHealth = GameObject.Find("Player").GetComponent <playerHealth> ();
	}
Ejemplo n.º 5
0
    NavMeshAgent nav;     //抓取enemy的nav组件

    void Awake()
    {
        player  = GameObject.FindGameObjectWithTag("Player").transform; //绑定玩家
        pHealth = player.GetComponent <playerHealth> ();                //绑定玩家生命值
        eHealth = GetComponent <enemyHealth> ();                        //绑定当前enemy生命值
        nav     = GetComponent <NavMeshAgent>();                        //绑定nav组件
    }
Ejemplo n.º 6
0
    //we want to use the player as a reference for animating and giving a simple AI.
    void Start()
    {
        Player           = GameObject.Find("Player");
        ControllerScript = Player.GetComponent <PlayerController> ();
        PHealthScript    = Player.GetComponent <playerHealth> ();

        controller = GetComponent <CharacterController> ();
        rend       = GetComponent <SpriteRenderer> ();
        target     = GameObject.FindGameObjectWithTag("Player");
        //Physics.IgnoreCollision (target.GetComponent<Collider> (), GetComponent<Collider> ());
        Physics.IgnoreCollision(target.transform.root.GetComponent <Collider> (), GetComponent <Collider> ());
        //Physics.IgnoreCollision (SlashWave.GetComponent<BoxCollider> (), GetComponent<Collider> ());

        origX = transform.localScale.x;
        //here it makes it ignore other enemy colliders so they can't get caught on each other.
        GameObject[] enemies = GameObject.FindGameObjectsWithTag("enemy");

        foreach (GameObject en in enemies)
        {
            if (en.GetComponent <Collider> () != GetComponent <Collider> ())
            {
                Physics.IgnoreCollision(GetComponent <Collider> (), en.GetComponent <Collider> ());
            }
        }
        bullet = Instantiate(enemyBullet, bulletPosition.position, Quaternion.Euler(0, 0, 0)) as GameObject;
        bullet.GetComponent <SpriteRenderer> ().enabled = false;
        bulletrb     = bullet.GetComponent <Rigidbody> ();
        bulletScript = bullet.GetComponent <enemyBullet> ();

        HealthScript = GetComponent <enemyHealth> ();
    }
Ejemplo n.º 7
0
    void Start()
    {
        zState = State.MovingToHouse;

        pHealthScript = Object.FindObjectOfType <playerHealth>();
        myZombAgent.SetDestination(houseTransform.position);
    }
Ejemplo n.º 8
0
 void Awake()
 {
     Gplayer      = GameObject.FindGameObjectWithTag("Player").transform;
     playerhealth = Gplayer.GetComponent <playerHealth> ();
     enemyhealth  = GetComponent <EnemyHealth> ();
     nav          = GetComponent <NavMeshAgent> ();
 }
Ejemplo n.º 9
0
    void OnTriggerStay2D(Collider2D other)
    {
        if (other.tag == "Player" && nextDamage < Time.time) //tag w unity
        {
            playerHealth thePlayerHealth = other.gameObject.GetComponent <playerHealth>();
            //odwolanie do skryptu
            thePlayerHealth.addDamage(damage);
            nextDamage = Time.time + damageRate;

            pushBack(other.transform);
        }

        void pushBack(Transform pushedObject) //push backward, dostep do poruszania sie po czasie;
        {
            Vector2 pushDirection = new Vector2(0, (pushedObject.position.y - transform.position.y)).normalized;

            //direction of push - opposite to direction that is pushin, normalize ma wartosc 1
            //kierunek odwrotny do wektora
            pushDirection *= pushBackForce;                                            //not normalized
            Rigidbody2D pushRB = pushedObject.gameObject.GetComponent <Rigidbody2D>(); //RB popychanego obiektu

            pushRB.velocity = Vector2.zero;
            pushRB.AddForce(pushDirection, ForceMode2D.Impulse); //impuls albo sila wybuch
        }
    }
Ejemplo n.º 10
0
    void fire(GameObject bulletEmitter)
    {
        if (Time.time - lastFireTime > 1)
        {
            GameObject player = GameObject.Find("Main Character Doesn't Run(Clone)");

            playerHealth health = player.GetComponent <playerHealth>();

            if (health.dead == false)
            {
                lastFireTime = Time.time;

                //Get the bulletEmitter to rotate towards the player
                Vector3 dir   = player.transform.position - bulletEmitter.transform.position;
                float   angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
                bulletEmitter.transform.rotation = Quaternion.Euler(0f, 0f, angle);

                //Get bullet
                GameObject bullet = Instantiate(bulletPrefab, bulletEmitter.transform.position, bulletEmitter.transform.rotation);

                bullet.GetComponent <turretBulletBeahviour>().passArgs(bulletEmitter.transform);

                AudioSource.PlayClipAtPoint(fireSound, bulletEmitter.transform.position);

                //Destroy bullet after 2 seconds
                Destroy(bullet, 2);
            }
        }
    }
Ejemplo n.º 11
0
 void Awake()
 {
     if (pHealth == null)
     {
         pHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <playerHealth>();
     }
 }
Ejemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        Player           = GameObject.Find("Player");
        ControllerScript = Player.GetComponent <PlayerController> ();
        PHealthScript    = Player.GetComponent <playerHealth> ();

        controller = GetComponent <CharacterController> ();
        controller.detectCollisions = false;

        target = GameObject.FindGameObjectWithTag("Player");
        //Physics.IgnoreCollision (target.GetComponent<Collider> (), GetComponent<Collider> ());
        Physics.IgnoreCollision(target.transform.root.GetComponent <Collider> (), GetComponent <Collider> ());


        Devilchu = GameObject.FindGameObjectWithTag("Devilchu");
        Physics.IgnoreCollision(Devilchu.transform.root.GetComponent <Collider> (), GetComponent <Collider> ());

        MyAnimation = gameObject.transform.FindChild("Animation").GetComponent <Animator> ();

        SlashWave = gameObject.transform.FindChild("Animation/LeafBody/LeafLLeg/SlashWave").gameObject;
        SlashWave.GetComponent <BoxCollider> ().enabled    = false;
        SlashWave.GetComponent <SpriteRenderer> ().enabled = false;

        HealthScript = gameObject.GetComponent <enemyHealth> ();
    }
Ejemplo n.º 13
0
 // Use this for initialization
 void Start()
 {
     words        = GetComponent <UnityEngine.UI.Text> ();
     player       = GameObject.Find("Player");
     playerHealth = player.GetComponent <playerHealth> ();
     //bomber = player.GetComponent<shootBomb> ();
 }
Ejemplo n.º 14
0
 // Use this for initialization
 void Start()
 {
     redPots      = 2;
     redNum       = GameObject.Find("redNum").GetComponent <Text>();
     playerHealth = GameObject.Find("Player").GetComponent <playerHealth>();
     playerAttack = GameObject.Find("trigger").GetComponent <playerAttack> ();
 }
    public AudioClip explosionAudio; //Som da explosao

    // Start is called before the first frame update
    void Awake()
    {
        Vector3 explosionPos = transform.position;                          //Pega a posição do objeto pra criar a Overlap Sphere

        Collider[] colliders = Physics.OverlapSphere(explosionPos, radius); //Cria a overlap sphere naquele ponto com aquele raio
        foreach (Collider hit in colliders)
        {
            Rigidbody rb = hit.GetComponent <Rigidbody>(); //Pega o rigidbody do que foi acertado
            //Se rb foi encontrado no objeto
            if (rb != null)
            {
                Debug.Log("Acertou");
                //Built-in function --- Forca da explosao, ponto da onde explodiu, raio
                //Modificador que joga pra cima, modo de forca = impulso
                rb.AddExplosionForce(power, explosionPos, radius, 3.0f, ForceMode.Impulse);
                if (hit.tag == "Player")
                {
                    playerHealth thePlayerHealth = hit.gameObject.GetComponent <playerHealth>(); //Pq aqui é so o Collider
                    thePlayerHealth.addDamage(damage);
                }
                else if (hit.tag == "Enemy")
                {
                    enemyHealth theEnemyHealth = hit.gameObject.GetComponent <enemyHealth>();
                    theEnemyHealth.addDamage(damage);
                    theEnemyHealth.addFire();
                }
            }
        }
        AudioSource.PlayClipAtPoint(explosionAudio, transform.position, 1f);
    }
Ejemplo n.º 16
0
    // funcion atacar, cuando el jugador esta en rango
    private void AttackPlayer()
    {
        //inmobilizamos al enemigo
        agent.SetDestination(transform.position);
        Vector3 targetPosition = new Vector3(player.position.x, transform.position.y, player.position.z);

        transform.LookAt(targetPosition);
        // verificamos si estamos en cooldown
        if (!alreadyAttacked)
        {
            anim.SetTrigger(attack);
            alreadyAttacked = true;
            // comprobamos todos los colliders en rango a ver si alguno es el jugador
            Collider[] hits = Physics.OverlapBox(attack_area.transform.position + attack_area.center, attack_area.size / 2, Camera.main.transform.rotation);
            foreach (Collider obj in hits)
            {
                print(obj);
                playerHealth obj_health = obj.gameObject.GetComponent <playerHealth>();
                if (obj_health)
                {
                    obj_health.receive_damage(2);
                }
            }

            alreadyAttacked = true;
            // cooldown
            Invoke(nameof(ResetAttack), timeBetweenAttacks);
        }
    }
Ejemplo n.º 17
0
    // Use this for initialization
    void Start()
    {
        Player           = GameObject.Find("Player");
        ControllerScript = Player.GetComponent <PlayerController> ();
        HealthScript     = Player.GetComponent <playerHealth> ();


        isAlive = true;
        rend    = GetComponent <SpriteRenderer> ();

        if (isBigBlock)
        {
            Explosion.startLifetime = 1.5f;
            Explosion.startSize     = 0.7f;
            Explosion.maxParticles  = 30;
            Explosion.startSpeed    = 1.0f;
        }
        else
        {
            Explosion.startLifetime = 0.56f;
            Explosion.startSize     = 0.65f;
            Explosion.maxParticles  = 25;
        }
        controller = GetComponent <CharacterController> ();
        controller.detectCollisions = false;

        Physics.IgnoreCollision(Player.transform.root.GetComponent <Collider> (), GetComponent <Collider> ());
    }
    public override void Deactivate(GameObject player)
    {
        playerHealth ph = player.GetComponent <playerHealth> ();

        ph.DecreaseCurrentDamage(damage);
        Debug.Log("Players damage has decreased by " + damage);
    }
Ejemplo n.º 19
0
    // Use this for initialization
    void Start()
    {
        Vector3 explosionPos = transform.position;

        Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
        foreach (Collider hit in colliders)
        {
            Rigidbody rb = hit.GetComponent <Rigidbody>();

            if (rb != null)
            {
                rb.AddExplosionForce(power, explosionPos, radius, 3.0f, ForceMode.Impulse);
            }
            if (hit.tag == "Player")
            {
                playerHealth thePlayerHealth = hit.gameObject.GetComponent <playerHealth>();
                thePlayerHealth.addDamage(damage);
            }
            else if (hit.tag == "Enemy")
            {
                enemyHealth theEnemyHealth = hit.gameObject.GetComponent <enemyHealth>();
                theEnemyHealth.addDamage(damage);
            }
        }
    }
Ejemplo n.º 20
0
    void Awake()
    {
        anim = GetComponent <Animator>();

        player       = GameObject.FindGameObjectWithTag("Player");
        playerHealth = player.GetComponent <playerHealth>();
    }
Ejemplo n.º 21
0
 void Awake()
 {
     if (pHealth == null)
     {
         pHealth = GameObject.FindGameObjectWithTag("Player").GetComponent<playerHealth>();
     }
 }
Ejemplo n.º 22
0
 void Start()
 {
     // Setting up the references.
     player       = GameObject.Find("Player");
     playerHealth = player.GetComponent <playerHealth>();
     anim         = GetComponent <Animator>();
 }
Ejemplo n.º 23
0
    void OnTriggerEnter(Collider other)
    {
        Instantiate(explosionParticle, transform.position, transform.rotation);

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius);

        for (int i = 0; i < colliders.Length; i++)
        {
            Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();
            if (!targetRigidbody)
            {
                continue;
            }

            targetRigidbody.AddExplosionForce(explosionForce, transform.position, radius);

            playerHealth targetHealth = targetRigidbody.GetComponent <playerHealth>();

            if (!targetHealth)
            {
                continue;
            }

            float damage = CalculateDamage(targetRigidbody.position);

            targetHealth.TakeDamage(damage);
        }
        Destroy(gameObject);
    }
 // Use this for initialization
 void Start()
 {
     nextDamage      = Time.time;
     thePlayer       = GameObject.FindGameObjectWithTag("Player");
     thePlayerHealth = thePlayer.GetComponent <playerHealth>();
     thisObject      = GameObject.FindGameObjectWithTag("Electric");
     InvokeRepeating("DisappearanceLogic", 0, 1f);
 }
 void Start()
 {
     mouth = gameObject.transform.Find("Lion_Mouth").gameObject;
     player = GameObject.FindWithTag ("P1");
     mouth.active = false;
     anim = GetComponent<Animator> ();
     playerhealth = player.GetComponent<playerHealth>();
 }
Ejemplo n.º 26
0
    private void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player").transform;

        playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <playerHealth>();

        target = new Vector2(player.position.x, player.position.y);
    }
Ejemplo n.º 27
0
    // Use this for initialization
    void Start()
    {
        player = FindObjectOfType <PlayerController> ();

        camera = FindObjectOfType <FollowCamera> ();

        forHealthFull = FindObjectOfType <playerHealth> ();
    }
Ejemplo n.º 28
0
 void OnTriggerStay2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         playerHealth die = other.gameObject.GetComponent <playerHealth>();
         die.makeDead();
     }
 }
Ejemplo n.º 29
0
    //bool isDead;


    void Awake()
    {
        pHealth     = GameObject.FindGameObjectWithTag("Player").GetComponent <playerHealth>();
        anim        = GetComponent <Animator>();       //绑定动画
        pMovement   = GetComponent <playerMovement>(); //绑定自定义引动脚本
        pShooting   = GetComponentInChildren <playerShoot>();
        currentTime = startingTime;                    //设置初始生命值
    }
Ejemplo n.º 30
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         playerHealth playerWins = other.gameObject.GetComponent <playerHealth> ();
         playerWins.winGame();
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (scoreController == null)
     {
         scoreController = scoreInfo.healthController;
     }
     scoreDisplay.text = "Kills: " + scoreController.killCount + " / " + scoreNeeded;
 }
Ejemplo n.º 32
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         playerHealth playerFell = other.GetComponent <playerHealth>();
         playerFell.winGame();
     }
 }
Ejemplo n.º 33
0
 void Start()
 {
     player = GameObject.FindGameObjectWithTag ("Player");
     player_Health = player.gameObject.GetComponent <playerHealth> ();
     healthRect=new Rect(Screen.width/10,Screen.height*8/10, Screen.width / 3, Screen.height / 50);
     healthTexture = new Texture2D(1, 1);
     healthTexture.SetPixel(0, 0, Color.green);
     healthTexture.Apply ();
 }
Ejemplo n.º 34
0
    private void Awake()
    {
        gPoints = GameObject.FindWithTag("Player").GetComponent<growPoints>();
        pHealth = GameObject.FindGameObjectWithTag("Player").GetComponent<playerHealth>();
        pEnergy = GameObject.FindGameObjectWithTag("Player").GetComponent<playerEnergy>();

        Top = GameObject.Find("Top").GetComponent<BoxCollider>();
        Bot = GameObject.Find("Bottom").GetComponent<BoxCollider>();
        Left = GameObject.Find("Left").GetComponent<BoxCollider>();
        Right = GameObject.Find("Right").GetComponent<BoxCollider>();
    }
Ejemplo n.º 35
0
    void Start()
    {
        BlackMask = GameObject.Find ("Black Mask");
        Eve = GameObject.Find ("Eve");

        blackMaskController = BlackMask.GetComponent<BlackMaskController> ();
        eveController = Eve.GetComponent<EveController> ();

        blackMaskHealth = BlackMask.GetComponent<playerHealth> ();
        eveHealth = Eve.GetComponent<playerHealth> ();

        // set black mask as active
        blackMaskController.isActivePlayer = true;
        eveController.isActivePlayer = false;

        killed = 0;
    }
Ejemplo n.º 36
0
 private void Awake()
 {
     pHealth = GameObject.FindWithTag("Player").GetComponent<playerHealth>();
 }
Ejemplo n.º 37
0
    private void Start()
    {
        targetRotation = transform.rotation;

        body = transform.Find ("Body").gameObject;

        if (GetComponent<Rigidbody> ())
            rBody = GetComponent<Rigidbody> ();
        else
            Debug.LogError ("The character needs a rigidbody.");

        if (GetComponent<Animator> ()) {
            cAnimator = GetComponent<Animator> ();
            cAnimator.SetBool ("OnGround", true);
        }
        else
            Debug.LogError ("The character needs an animator.");

        if (GetComponent<playerHealth> ())
            health = GetComponent<playerHealth> ();
        else
            Debug.LogError ("The character needs health.");
    }
Ejemplo n.º 38
0
 private void Awake()
 {
     //energyFood = GameObject.FindWithTag("food").GetComponent<foodPills>();
     pHealth = gameObject.GetComponent<playerHealth>();
 }