Example #1
0
    // Update is called once per frame
    void Update()
    {
        gamemanagerscript = GameObject.FindObjectOfType <gamemanager> ();
        enemyscript       = gameObject.transform.parent.GetComponent <enemyscript> ();

        if (!gamemanagerscript.playerdeath)
        {
            playerposition = GameObject.FindObjectOfType <characterscript> ().GetComponent <characterscript> ().transform.position;
            difference     = transform.position - playerposition;

            if (difference.x <= 16f && difference.x >= 2f)
            {
                shooting = true;
            }
            else
            {
                shooting = false;
            }

            difference.Normalize();
            float rotz = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;              // find the angles in degrees


            if (Time.time > cooldowntimer && shooting)
            {
                cooldowntimer       = Time.time + firedelay;
                enemyscript.walking = false;
                gunanim.SetTrigger("shoot");
                Instantiate(muzzleflash, firepoint.position, transform.rotation);
                GameObject bulletinstance;
                bulletinstance = Instantiate(bullet, firepoint.position, transform.rotation) as GameObject;
                bulletinstance.GetComponent <Rigidbody2D> ().AddForce(difference * -700f);
            }
        }
    }
Example #2
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        enemyscript enemy = hitInfo.GetComponent <enemyscript>();

        enemy.TakeDamage(damage);
        Debug.Log("Hit");
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        HandleMovement(horizontal);
        HandleMovement1(vertical);
        Flip(horizontal);
        if (Input.GetKeyDown(runKey))
        {
            transform.position += new Vector3(speed * Time.deltaTime, 0.0f, 0.0f);
        }
        enemyscript ES = GameObject.FindGameObjectWithTag("Enemy").GetComponent <enemyscript>(); // referencing the enemyscript which holds the latched bool.

        if (ES.latched && takeDamage == false)                                                   // if the enemy is latched and the player is not already taking damage, the corroutine will start
        {
            StartCoroutine(TakeDamage(timeBetween, enemyDamage));
        }
        else if (!ES.latched)
        {
            takeDamage = false;
        }
        if (health <= 0 && dead == false)
        {
            transform.position = checkpoint.transform.position; // where frank will respawn.
        }
    }
 // Use this for initialization
 void Start()
 {
     controller        = GetComponent <CharacterController>();
     playerFacingRight = true;
     health            = 5; // displays in the inspector but has to be changed in script.
     maxHealth         = 5;
     takeDamage        = false;
     dead = false;
     // rigidPlayer = GetComponent<Rigidbody>();
     ES = GameObject.FindGameObjectWithTag("EnemySprite").GetComponent <enemyscript>();// referencing the enemyscript which holds the latched bool.
 }
 enemyscript ES;                      // gonna need some bools from the enemy too
 // Use this for initialization
 void Start()
 {
     currentSpawn = Random.Range(0, spawnPoints.Length);                                           // the current spawn is a random number between 0 and the length of the array
     maxSpawns    = spawnPoints.Length;                                                            // max spawns is equal to the spawn points array length
     playerSprite = GameObject.FindGameObjectWithTag("Player Model");                              // this is being used to reference the sprite rather than player holder... We will be de activating and re activating on death
     flickrSprite = GameObject.FindGameObjectWithTag("EnemySprite");                               // this is being used to referece the sprite of the enemy. will be de activating and re activating upon death
     PS           = GameObject.FindGameObjectWithTag("Player").GetComponent <playerScript> ();     // referencing the 3D player object... specifically the player script on the player object
     ES           = GameObject.FindGameObjectWithTag("EnemySprite").GetComponent <enemyscript> (); // referencing the 3D enemy object.. specifically the enemy script on the enemy object
     flickr       = GameObject.FindGameObjectWithTag("EnemySprite");                               // referecning the actual enemy 3D holder
     flickr.transform.position = spawnPoints [currentSpawn].transform.position;                    // the starting position of the flickr enemy
     StartCoroutine(EnemyAlive());                                                                 // start her up
 }
Example #6
0
    private void OnEnable()
    {
        myTarget = (enemyscript)target;
        soTarget = new SerializedObject(target);

        //health = soTarget.FindProperty("health");
        //deathEffect = soTarget.FindProperty("deathEffect");
        speed        = soTarget.FindProperty("speed");
        amplitude    = soTarget.FindProperty("amplitude");
        period       = soTarget.FindProperty("period");
        yChange      = soTarget.FindProperty("yChange");
        waitTime     = soTarget.FindProperty("waitTime");
        slideTime    = soTarget.FindProperty("slideTime");
        moveRight    = soTarget.FindProperty("moveRight");
        maxRadians   = soTarget.FindProperty("maxRadians");
        sideVelocity = soTarget.FindProperty("sideVelocity");
    }