コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        moveHorizontal = Input.GetAxis("Horizontal_P2");
        moveVertical   = Input.GetAxis("Vertical_P2");

        if (!myAttack)
        {
            Move();
            Attack();
            Defensive();
        }

        /*Vector2 position = new Vector2(Mathf.Clamp(transform.position.x, xMin, xMax),
         *  Mathf.Clamp(transform.position.y, yMin, yMax));
         * transform.position = position;*/
        if (hitPoints <= 0)
        {
            Dead();
        }

        if (damageTaken > 0)
        {
            hitPoints  -= damageTaken;
            damageTaken = 0;
            StartCoroutine("HurtColor");
            Instantiate(deathPrefab, transform.position, transform.rotation);
            SoundManagerController.PlaySound("Hit");
        }



        SpecialAttack();
    }
コード例 #2
0
 public void Activate()
 {
     SoundManagerController.PlaySound("Shield");
     poligonCollider.enabled = true;
     activated = true;
     animator.SetBool("Casting", true);
 }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        float xMov = Input.GetAxisRaw("Horizontal");
        float yMov = Input.GetAxisRaw("Vertical");
        float zMov = Input.GetAxisRaw("Jump");

        Vector3 movHorizontal = transform.right * xMov;
        Vector3 movVertical   = transform.forward * yMov;
        Vector3 movUp         = transform.up * zMov;

        velocity = (movHorizontal + movVertical + movUp).normalized * speed;

        transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivity);
        verticalLookRotation += Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivity;
        verticalLookRotation  = Mathf.Clamp(verticalLookRotation, -60, 60);
        cam.localEulerAngles  = Vector3.left * verticalLookRotation;
        enemyText.text        = "Monstruos Eliminados: " + enemyCount.ToString();

        if (count >= 13 && enemyCount >= 5 && !gano)
        {
            gano         = true;
            winText.text = "Felicidades Completaste el Nivel!! \nAlumno: Carlos Blanco \ndSimulación por Computadora \n";
            SoundManagerController.PlaySound("win");
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
        }
    }
コード例 #4
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Enemy"))
     {
         SoundManagerController.PlaySound("hit");
         other.gameObject.SetActive(false);
         FPController.IncrementaEnemyCount();
     }
 }
コード例 #5
0
 private void JumpListenner()
 {
     if (Input.GetKeyDown(jumpKey) && remainingJumps > 0)
     {
         InstantiateCloud();
         SoundManagerController.PlaySound("Jump");
         rb.velocity = Vector2.up * jumpForce;
         remainingJumps--;
     }
 }
コード例 #6
0
ファイル: BallController.cs プロジェクト: hiagolcm/MageDodge
    private void OnCollisionEnter2D(Collision2D collision)
    {
        SoundManagerController.PlaySound("Bounce");
        if (collision.gameObject.name == "Shield" || collision.gameObject.name == "RedShield")
        {
            cameraController.CamShake();

            Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
            direction.Normalize();
            rb.AddForce(direction * bounceForce);
        }
    }
コード例 #7
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Pick Up"))
     {
         SoundManagerController.PlaySound("ping");
         other.gameObject.SetActive(false);
         count++;
         SetCountText();
     }
     if (other.gameObject.CompareTag("Pieces"))
     {
         other.gameObject.SetActive(false);
     }
 }
コード例 #8
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.name == "Ball" && !dead)
        {
            timeController.SlowTrigger();
            //rb.velocity = new Vector2(0, 0);
            SoundManagerController.PlaySound("Dead");
            animator.SetTrigger("Dead");
            dead = true;
            scoreManager.TriggerWin(enemyPlayerIndex);
        }

        if (collision.gameObject.name == "Tilemap" && !isOnTheWall())
        {
            InstantiateCloud();
            SoundManagerController.PlaySound("HitTheGround");
        }
    }
コード例 #9
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F))
        {
            SoundManagerController.PlaySound("shoot");
            GameObject Temporary_Bullet_Handler;
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;

            Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);

            Rigidbody Temporary_RigidBody;
            Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent <Rigidbody>();

            Temporary_RigidBody.AddForce(transform.forward * Bullet_Forward_Force);

            Destroy(Temporary_Bullet_Handler, 10.0f);
        }
    }
コード例 #10
0
    private void Attack()
    {
        // My attack
        if (Input.GetButton("Fire1_P2") && !myAttack)
        {
            if (facingRight)
            {
                float x2 = transform.position.x + 0.5f;
                float y2 = transform.position.y;
                myAttack = Instantiate(attackPrefab, new Vector3(x2, y2), Quaternion.identity);
                myAttack.GetComponent <AttackController>().myEnemy = "Minion";
                SoundManagerController.PlaySound("Swish");
            }
            if (!facingRight)
            {
                float x2 = transform.position.x - 0.5f;
                float y2 = transform.position.y;
                myAttack = Instantiate(attackPrefab, new Vector3(x2, y2), Quaternion.identity);
                myAttack.GetComponent <AttackController>().myEnemy = "Minion";
                myAttack.GetComponent <SpriteRenderer>().flipX     = true;
                SoundManagerController.PlaySound("Swish");
            }
        }

        #region Janne Attack

        /*
         * if (Input.GetButton("Fire1") && Time.time > nextFire)
         * {
         *  nextFire = Time.time + attackSpeed;
         *  if (moveHorizontal < 0 && moveVertical > 0)
         *  {
         *      anim.SetTrigger("AttackUpSide");
         *      //Debug.Log("Player Attacks Up Side left");
         *  }
         *  if (moveHorizontal == -1 || moveHorizontal == 1 && moveVertical == 0)
         *  {
         *      anim.SetTrigger("Attack");
         *      //Debug.Log("Player Attacks left");
         *  }
         *  if (moveHorizontal < 0 && moveVertical < 0)
         *  {
         *      anim.SetTrigger("AttackDownSide");
         *      //Debug.Log("Player Down Side left");
         *  }
         *  if (moveHorizontal == 0 && moveVertical == -1)
         *  {
         *      anim.SetTrigger("AttackDown");
         *      //Debug.Log("Player Attacks Down");
         *  }
         *  if (moveHorizontal > 0 && moveVertical < 0)
         *  {
         *      anim.SetTrigger("AttackDownSide");
         *      //Debug.Log("Player Down Side right");
         *  }
         *
         *  if (moveHorizontal == 1 && moveVertical == 0)
         *  {
         *      anim.SetTrigger("Attack");
         *      //Debug.Log("Player Attacks right");
         *  }
         *
         *  if (moveHorizontal > 0 && moveVertical > 0)
         *  {
         *      anim.SetTrigger("AttackUpSide");
         *      //Debug.Log("Player Attacks upside right");
         *  }
         *  if (moveHorizontal == 0 && moveVertical == 1)
         *  {
         *      anim.SetTrigger("AttackUp");
         *      //Debug.Log("Player Attacks up");
         *
         *  } else
         *  {
         *      anim.SetTrigger("Attack");
         *  }
         * }
         *
         */

        /*
         *          float attackX = gameObject.transform.position.x + moveHorizontal;
         *  float attackY = gameObject.transform.position.y + moveVertical;
         *
         *   nextFire = Time.time + attackSpeed;
         *   if (moveHorizontal < 0 && moveVertical > 0)
         *   {
         *      //Debug.Log("Player Attacks Up Side left");
         *      spawnHitBox(attackX, attackY);
         *   }
         *   if (moveHorizontal == -1 || moveHorizontal == 1 && moveVertical == 0)
         *   {
         *      //Debug.Log("Player Attacks left");
         *      spawnHitBox(attackX, attackY);
         *  }
         *  if (moveHorizontal < 0 && moveVertical < 0)
         *   {
         *      //Debug.Log("Player Down Side left");
         *      spawnHitBox(attackX, attackY);
         *  }
         *  if (moveHorizontal == 0 && moveVertical == -1)
         *   {
         *      //Debug.Log("Player Attacks Down");
         *      spawnHitBox(attackX, attackY);
         *  }
         *  if (moveHorizontal > 0 && moveVertical < 0)
         *   {
         *      //Debug.Log("Player Down Side right");
         *      spawnHitBox(attackX, attackY);
         *  }
         *  if (moveHorizontal == 0 && moveVertical == 1)
         *  {
         *      //Debug.Log("Player Attacks up");
         *      spawnHitBox(attackX, attackY);
         *  }
         *  if (moveHorizontal > 0 && moveVertical > 0)
         *  {
         *      //Debug.Log("Player Attacks upside right");
         *      spawnHitBox(attackX, attackY);
         *  }
         *  /*if (moveHorizontal == 1 && moveVertical == 0)
         *  {
         *      anim.SetTrigger("Attack");
         *      //Debug.Log("Player Attacks right");
         *  }
         *  if (moveHorizontal > 0 && moveVertical > 0)
         *  {
         *      anim.SetTrigger("AttackUpSide");
         *      //Debug.Log("Player Attacks upside right");
         *  }
         *   else
         *  {
         *      anim.SetTrigger("Attack");
         *  }*/

        /*// Find X position
         * float xx = gameObject.transform.position.x;
         * if (moveHorizontal < transform.position.x - 1f)
         * {
         *  xx -= 1f;
         * }
         * else if (moveHorizontal > transform.position.x + 1f)
         * {
         *  xx += 1f;
         * }
         *
         * // Find Y position
         * float yy = gameObject.transform.position.y;
         * if (moveVertical < transform.position.y - 1f)
         * {
         *  yy -= 1f;
         * }
         * else if (moveVertical > transform.position.y + 1f)
         * {
         *  yy += 1f;
         * }
         */

        #endregion Janne Attack
    }
コード例 #11
0
    // Fixed Update
    private void FixedUpdate()
    {
        if (isControlled == false)
        {
            // States
            switch (state)
            {
            case States.idle:
                Idle();
                break;

            case States.chase:
                Chase();
                break;

            case States.attack:
                Attack();
                break;

            case States.flee:
                Flee();
                break;

            case States.dead:
                Dead();
                break;
            }
        }
        else if (isControlled == true)
        {
            // Movement
            if (!myAttack)
            {
                float moveHorizontal = Input.GetAxisRaw("Horizontal2");
                float moveVertical   = Input.GetAxisRaw("Vertical2");
                transform.Translate(new Vector3(moveHorizontal, moveVertical) * moveSpeed * Time.deltaTime * 3);

                if (moveHorizontal > 0 && !facingRight)
                {
                    facingRight = !facingRight;
                    Vector3 theScale = transform.localScale;
                    theScale.x          *= -1;
                    transform.localScale = theScale;
                }
                else if (moveHorizontal < 0 && facingRight)
                {
                    facingRight = !facingRight;
                    Vector3 theScale = transform.localScale;
                    theScale.x          *= -1;
                    transform.localScale = theScale;
                }
            }

            // Health
            if (hitPoints <= 0)
            {
                Instantiate(deathPrefab, transform.position, transform.rotation);
                SoundManagerController.PlaySound("GoblinDeath");
                Destroy(gameObject);
            }

            // My attack
            if (Input.GetButton("Fire2") && !myAttack)
            {
                if (facingRight)
                {
                    float x2 = transform.position.x + 0.5f;
                    float y2 = transform.position.y;
                    myAttack = Instantiate(attackPrefab, new Vector3(x2, y2), Quaternion.identity);
                    myAttack.GetComponent <AttackController>().myEnemy = "Player";
                    SoundManagerController.PlaySound("Swish");
                }
                if (!facingRight)
                {
                    float x2 = transform.position.x - 0.5f;
                    float y2 = transform.position.y;
                    myAttack = Instantiate(attackPrefab, new Vector3(x2, y2), Quaternion.identity);
                    myAttack.GetComponent <AttackController>().myEnemy = "Player";
                    myAttack.GetComponent <SpriteRenderer>().flipX     = true;
                    SoundManagerController.PlaySound("Swish");
                }
            }
        }



        // Attack speed
        if (timeSinceLastAttack > 0)
        {
            timeSinceLastAttack -= Time.deltaTime;
        }

        if (damageTaken > 0)
        {
            hitPoints  -= damageTaken;
            damageTaken = 0;
            StartCoroutine("HurtColor");
            Instantiate(deathPrefab, transform.position, transform.rotation);
            SoundManagerController.PlaySound("Hit");
        }

        // Health/Death
        if (hitPoints <= 0)
        {
            state = States.dead;
        }
    }
コード例 #12
0
 // Dead if dead
 private void Dead()
 {
     Instantiate(deathPrefab, transform.position, transform.rotation);
     SoundManagerController.PlaySound("GoblinDeath");
     Destroy(gameObject);
 }
コード例 #13
0
    // Attack Otters, if they exist inside attack range
    private void Attack()
    {
        //--- Behaviour
        Debug.Log("My state is now attack");

        // Attack
        if (target && Vector2.Distance(transform.position, target.position) < attackRange)
        {
            if (!ranged && !myAttack)
            {
                // Create attack
                float x2 = target.position.x;
                float y2 = target.position.y;
                myAttack = Instantiate(attackPrefab, new Vector3(x2, y2), Quaternion.identity);
                myAttack.GetComponent <AttackController>().myEnemy = "Player";
                if (!facingRight)
                {
                    myAttack.GetComponent <SpriteRenderer>().flipX = true;
                }
                SoundManagerController.PlaySound("Swish");
            }
            else if (ranged && timeSinceLastAttack <= 0)
            {
                timeSinceLastAttack = attackSpeed;
                float x2 = transform.position.x;
                float y2 = transform.position.y;
                myAttack = Instantiate(attackPrefab, new Vector3(x2, y2), Quaternion.identity);
                myAttack.GetComponent <BulletController>().target = target;
                SoundManagerController.PlaySound("Gun");
            }
        }

        //--- Trigger
        if (!ranged && !myAttack)
        {
            // No Otters?
            if (!target)
            {
                state = States.idle;
            }
            // Otters too far away?
            else if (Vector2.Distance(transform.position, target.position) > attackRange)
            {
                state = States.chase;
            }
        }
        else if (ranged)
        {
            // No Otters?
            if (!target)
            {
                state = States.idle;
            }
            // Otters too far away?
            else if (Vector2.Distance(transform.position, target.position) > attackRange)
            {
                state = States.chase;
            }
            // Otters too close?
            else if (Vector2.Distance(transform.position, target.position) < fleeRange)
            {
                state = States.flee;
            }
        }

        //--- Audiovisual
        Flip();

        //state = States.idle;
    }