/*public void resetHealthSprite()
     * {
     *  if (heartUp.GetComponent<HealthPack>().hasHealthPack == true)
     *  {
     *      healthDeduction*=0;
     *      heartUp.GetComponent<HealthPack>().hasHealthPack = false;
     *  }
     * }*/
    public void takeDamage(float damage)
    {
        if (healthDeduction <= healthSprites.Length)
        {
            healthDeduction++;
        }
        if (damage <= 0)
        {
            return;
        }
        // ShowNextHealthSprite();

        currentHealth     -= damage;
        healthSlider.value = currentHealth;
        Coroutine flash;

        flash = StartCoroutine(Flash());

        if (player != null && currentHealth > 0)
        {
            AudioClip clip = hurtSound;
            myAudioSource.PlayOneShot(clip);
        }


        if (currentHealth <= 0)
        {
            currentHealth = 0;
            AudioClip clip = deathSound;
            myAudioSource.PlayOneShot(clip);
            player.GetComponent <player>().isDead = true;
            StartCoroutine(Death(this.gameObject));
            StartCoroutine(Wait());
        }
    }
Exemplo n.º 2
0
    private Animator anim;                      // The animator for the player

    void Start()
    {
        // Getting components
        rb   = plyr.GetComponent <Rigidbody2D>();
        bx   = plyr.GetComponent <BoxCollider2D>();
        anim = plyr.GetComponent <Animator>();
    }
Exemplo n.º 3
0
 public void levelWin()
 {
     player.completeLevelUI.SetActive(true);
     player.enabled = false;
     Destroy(player.GetComponent <Rigidbody>());
     //open new level
     level += 1;
     Invoke("loadNextLevel", delay);
 }
Exemplo n.º 4
0
    IEnumerator sSacrifice()
    {
        FadeIn();

        yield return(new WaitForSeconds(fadetime / 2));

        Obj.GetComponent <SpriteRenderer>().enabled           = false;
        Obj.GetComponentInChildren <SpriteRenderer>().enabled = false;
        yield return(new WaitForSeconds(fadetime / 2));

        Obj.GetComponent <SpriteRenderer>().enabled           = true;
        Obj.GetComponentInChildren <SpriteRenderer>().enabled = true;

        Sacrifice();
        FadeOut();
    }
Exemplo n.º 5
0
 // Use this for initialization
 void Start()
 {
     playerCharacter    = GameObject.Find("player").GetComponent <player>();
     weaponManager      = playerCharacter.GetComponent <WeaponManager>();
     healthBar.maxValue = playerCharacter.healthMax;
     //AmmoText = transform.Find("PlayerAmmoText").GetComponent<Text>();
     //ExplosiveText = transform.Find("PlayerExplosiveText").GetComponent<Text>();
 }
Exemplo n.º 6
0
    void HandleOnLocalPlayerJoin(player player)
    {
        playershoot = player.GetComponent <PlayerShoot>();

        /// playershoot.onweaponswitch += handleonweaponswitch;


        // Reloader = playershoot.ActiveWeapon.reloader;


        //  Reloader.OnammoChanged += handledonammochange;
    }
Exemplo n.º 7
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        player player = collision.collider.gameObject.GetComponent <player> ();

        if (player != null)
        {
            if ((player.state == aggregateState.SOLID && state == aggregateState.GAS) | (player.state == aggregateState.GAS && state == aggregateState.SOLID))
            {
                if (isPlayer || player.isPlayer)
                {
                    handler.stateReached(aggregateState.LIQUID);
                }
                state = aggregateState.LIQUID;
                GetComponent <SpriteRenderer> ().sprite    = liquid.GetComponent <SpriteRenderer> ().sprite;
                GetComponent <PolygonCollider2D> ().points = liquid.GetComponent <PolygonCollider2D> ().points;
                player.state = aggregateState.LIQUID;
                player.GetComponent <SpriteRenderer> ().sprite    = liquid.GetComponent <SpriteRenderer> ().sprite;
                player.GetComponent <PolygonCollider2D> ().points = liquid.GetComponent <PolygonCollider2D> ().points;
            }
        }
    }
Exemplo n.º 8
0
    void Update()
    {
        Vector2 directionalInput = new Vector2(Input.GetAxisRaw(horizontal), Input.GetAxisRaw(vertical));

        // Debug.Log (player.getArmRotation ());
        //Debug.Log(Input.GetAxisRaw("Horizontal2"));
        // player.setArmRotation(Mathf.Atan2 (Input.GetAxisRaw("Vertical2"), Input.GetAxisRaw("Horizontal2")) * 360 / 2 / Mathf.PI);
        if (Input.GetAxisRaw(horizontalR) == 0 && Input.GetAxisRaw(verticalR) == 0)
        {
            player.setArmRotation(0);
        }
        else if (!player.GetComponent <playerController> ().getIsFacingRight())
        {
            player.setArmRotation(Mathf.Atan2(Input.GetAxisRaw(verticalR), -Input.GetAxisRaw(horizontalR)) * 360 / 2 / Mathf.PI);
        }
        else
        {
            player.setArmRotation(Mathf.Atan2(Input.GetAxisRaw(verticalR), Input.GetAxisRaw(horizontalR)) * 360 / 2 / Mathf.PI);
        }

        player.SetDirectionalInput(directionalInput);

        if (Input.GetButtonDown(jump) && player.getjumpCount() < 2)
        {
            //player.doubleJump ();
            player.OnJumpInputDown();
        }        //else if (Input.GetButtonDown(jump)) {
        //player.OnJumpInputDown ();
        //}
        if (Input.GetButtonUp(jump))
        {
            player.OnJumpInputUp();
        }

        if (Input.GetButton(fire))
        {
            if (!fired)
            {
                player.Fire(0);
                fired = true;
                StartCoroutine(Shoot());
            }
        }
        if (Input.GetButton(altFire))
        {
            if (!fired)
            {
                player.Fire(1);
                fired = true;
                StartCoroutine(ShootAlt());
            }
        }
    }
Exemplo n.º 9
0
    private Animator anim;                  // The animator for the hotdog stand

    void Start()
    {
        // Getting components
        sr   = plyr.GetComponent <SpriteRenderer>();
        anim = this.GetComponent <Animator>();
    }
Exemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit rayHit;
        Vector3    fd = transform.TransformDirection(Vector3.forward);

        if (Input.GetKeyDown("e") && puz_show == true && showing == false)
        {
            puzzle_menu.gameObject.SetActive(false);
            character.GetComponent <Character_Controller>().enabled = true;
            puz_show = false;
            character.transform.GetChild(0).GetComponent <Camera_Mouse_Look>().enabled = true;
            character.transform.GetChild(0).GetComponent <Camera_Mouse_Look>().NoCursorDisplay();

            Cursor.lockState = CursorLockMode.Locked;
        }

        else if (Physics.Raycast(transform.position, fd, out rayHit, ray_dist))
        {
            if (rayHit.collider.isTrigger)
            {
                if (isInteracting == false)
                {
                    if (interactIcon != null)
                    {
                        interactIcon.enabled = true;
                    }
                    if (!showBook)
                    {
                        if (rayHit.collider.CompareTag("Book"))
                        {
                            rayHit.collider.GetComponent <Book>().DisplayText(true);
                        }
                    }
                    if (rayHit.collider.CompareTag("Plaque"))
                    {
                        rayHit.collider.GetComponent <Plaque>().ChangeText();
                    }
                    if (rayHit.collider.CompareTag("Hide"))
                    {
                        rayHit.collider.GetComponent <Plaque>().ChangeText();
                    }

                    if (Input.GetKeyDown("e"))
                    {
                        if (rayHit.collider.CompareTag("Item"))
                        {
                            rayHit.collider.GetComponent <Pickup_Item>().Pickup();
                        }

                        else if (rayHit.collider.CompareTag("Puzzle"))
                        {
                            puzzle_menu.gameObject.SetActive(true);
                            character.GetComponent <Character_Controller>().enabled = false;
                            puz_show = true;
                            character.transform.GetChild(0).GetComponent <Camera_Mouse_Look>().CursorDisplay();
                            character.transform.GetChild(0).GetComponent <Camera_Mouse_Look>().enabled = false;
                            Cursor.lockState = CursorLockMode.None;
                        }

                        else if (rayHit.collider.CompareTag("UnlockedDoor"))
                        {
                            rayHit.collider.GetComponent <AudioSource>().Play();
                            rayHit.collider.GetComponent <RotateDoor>().Rotate();
                            rayHit.collider.GetComponent <BoxCollider>().enabled = false;
                        }
                        else if (rayHit.collider.CompareTag("Door"))
                        {
                            if (rayHit.collider.GetComponent <Use_Item>().Use_Item_Door() == true)
                            {
                                rayHit.collider.GetComponent <AudioSource>().Play();
                                rayHit.collider.GetComponent <RotateDoor>().Rotate();
                                rayHit.collider.GetComponent <BoxCollider>().enabled = false;
                            }
                        }
                        else if (rayHit.collider.CompareTag("Fireplace"))
                        {
                            if (rayHit.collider.GetComponent <Use_Item>().Use_Item_Lighter() == true)
                            {
                                Inventory.instance.UpdateSlotUI();
                            }
                        }
                        else if (rayHit.collider.CompareTag("Note") && puz_show == false)
                        {
                            lastNote = rayHit.collider.GetComponent <Pickup_Item>().item.display_name;
                            rayHit.collider.GetComponent <Note>().ShowNoteImage();
                            noteUI = true;
                        }

                        else if (rayHit.collider.CompareTag("Workbench"))
                        {
                            rayHit.collider.GetComponent <Workbench>().WorkbenchSolve();
                            rayHit.collider.GetComponent <Workbench>().isSolved();
                        }

                        else if (rayHit.collider.CompareTag("Scrap"))
                        {
                            rayHit.collider.GetComponent <Pickup_Item>().Pickup();
                        }

                        else if (rayHit.collider.CompareTag("Gun"))
                        {
                            rayHit.collider.GetComponent <Pickup_Item>().Pickup();
                            gunCam.SetActive(true);
                        }

                        else if (rayHit.collider.CompareTag("Book"))
                        {
                            showBook = rayHit.collider.GetComponent <Book>().Puzzle();
                        }

                        else if (rayHit.collider.CompareTag("Record"))
                        {
                            rayHit.collider.GetComponent <Pickup_Item>().Pickup();
                        }
                        else if (rayHit.collider.CompareTag("RecordPlayer"))
                        {
                            rayHit.collider.GetComponent <RecordPlayer>().RecordPlayerSolve();
                        }
                        else if (rayHit.collider.CompareTag("BookReset"))
                        {
                            rayHit.collider.GetComponent <LibraryButton>().EnablePart2();
                            showBook = false;
                        }
                        else if (rayHit.collider.CompareTag("Flashlight"))
                        {
                            rayHit.collider.GetComponent <Pickup_Item>().Pickup();
                        }
                    }
                }
            }
        }
        else
        {
            interactIcon.enabled = false;
        }

        if (Input.GetKeyDown(KeyCode.Tab) && puz_show == false)
        {
            if (noteUI == true)
            {
                if (Inventory.instance.IsItem(lastNote))
                {
                    noteUI = false;
                }
            }

            if (showing == false && noteUI == false)
            {
                inventory_menu.gameObject.SetActive(true);
                showing        = true;
                Time.timeScale = 0;
                character.transform.GetChild(0).GetComponent <Camera_Mouse_Look>().enabled = false;
                character.transform.GetChild(0).GetComponent <Camera_Mouse_Look>().CursorDisplay();
            }

            else
            {
                inventory_menu.gameObject.SetActive(false);
                showing        = false;
                Time.timeScale = 1;
                character.transform.GetChild(0).GetComponent <Camera_Mouse_Look>().enabled = true;
                character.transform.GetChild(0).GetComponent <Camera_Mouse_Look>().NoCursorDisplay();
            }
        }
    }
Exemplo n.º 11
0
    private Animator anim;                  // The animator for the player

    void Start()
    {
        // Getting the components
        rb   = plyr.GetComponent <Rigidbody2D>();
        anim = plyr.GetComponent <Animator>();
    }
Exemplo n.º 12
0
 void boxSelect()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (!ishold)
         {
             Debug.Log(Input.GetMouseButtonDown(0));
             box1   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             ishold = true;
         }
     }
     if (ishold)
     {
         lineLeft.enabled  = true;
         lineRight.enabled = true;
         lineDown.enabled  = true;
         lineUp.enabled    = true;
         Vector2   boxd = Camera.main.ScreenToWorldPoint(Input.mousePosition);;
         float     x1   = box1.x;
         float     x2   = boxd.x;
         float     y1   = box1.y;
         float     y2   = boxd.y;
         Vector3   h1   = new Vector3(x1, y1, 0);
         Vector3   h2   = new Vector3(x1, y2, 0);
         Vector3   q1   = new Vector3(x2, y1, 0);
         Vector3   q2   = new Vector3(x2, y2, 0);
         Vector3   z1   = new Vector3(x1, y1, 0);
         Vector3   z2   = new Vector3(x2, y1, 0);
         Vector3   c1   = new Vector3(x1, y2, 0);
         Vector3   c2   = new Vector3(x2, y2, 0);
         Vector3[] hh   = new Vector3[] { h1, h2 };
         Vector3[] qq   = new Vector3[] { q1, q2 };
         Vector3[] zz   = new Vector3[] { z1, z2 };
         Vector3[] cc   = new Vector3[] { c1, c2 };
         if (x1 < x2)
         {
             lineLeft.SetPositions(hh);
             lineRight.SetPositions(qq);
         }
         else
         {
             lineRight.SetPositions(hh);
             lineLeft.SetPositions(qq);
         }
         if (y1 > y2)
         {
             lineUp.SetPositions(zz);
             lineDown.SetPositions(cc);
         }
         else
         {
             lineDown.SetPositions(zz);
             lineUp.SetPositions(cc);
         }
     }
     if (Input.GetMouseButtonUp(0))
     {
         lineLeft.enabled  = false;
         lineRight.enabled = false;
         lineDown.enabled  = false;
         lineUp.enabled    = false;
         box2    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         ishold  = false;
         myunits = Physics2D.OverlapAreaAll(box1, box2);
         List <GameObject> boxChoice = new List <GameObject>();
         if (myunits != null)
         {
             foreach (Collider2D unit in myunits)
             {
                 player mine1 = unit.GetComponent <player>();
                 if (mine1 != null)
                 {
                     if (mine1.team == 1)
                     {
                         mine1.isChosen = true;
                         boxChoice.Add(unit.gameObject);
                     }
                 }
                 if (boxChoice.Count > 0)
                 {
                     foreach (GameObject a in myUnit)
                     {
                         bool k = false;
                         foreach (GameObject b in boxChoice)
                         {
                             if (a == b)
                             {
                                 k = true;
                                 break;
                             }
                         }
                         if (!k)
                         {
                             a.GetComponent <player>().isChosen = false;
                         }
                     }
                     myUnit = boxChoice;
                 }
             }
         }
     }
 }
Exemplo n.º 13
0
    void FixedUpdate()
    {
        GetComponent <BoxCollider>().enabled = !HaveBall;
        if (HaveBall)
        {
            rigdbody.constraints = (RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ);
        }
        else
        {
            rigdbody.constraints = (RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ);
        }

        anim.SetBool("Walk", !(rigdbody.velocity.magnitude < 1));
        anim.SetBool("Run", Input.GetKey(KeyCode.E));


        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");

        move(new Vector3(h, 0, v), Input.GetKey(KeyCode.E));

        if (!HaveBall)
        {
            var lookPos = Ball.transform.position - transform.position;
            lookPos.y = 0;
            var rotation = Quaternion.LookRotation(lookPos);
            transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 5);
        }
        else if (HaveBall)
        {
            if (!(Ball.GetComponent <Rigidbody>().velocity.magnitude < 1))
            {
                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Ball.GetComponent <Rigidbody>().velocity.normalized), Time.deltaTime * 10.5f);
            }
        }



        if (HaveBall)
        {
            if (Input.GetKey(KeyCode.X))
            {
                float   horizontal1 = Input.GetAxis("Horizontal");
                float   vertical1   = Input.GetAxis("Vertical");
                Vector3 direction   = new Vector3(horizontal1, 0f, vertical1);
                if (Mathf.Approximately(direction.magnitude, 0f))
                {
                    direction = transform.forward;
                }
                Vector3 dirToTarget = (GoalPost.transform.position - transform.position).normalized;
                shotdirec = new[] { GoalPost.transform.GetChild(0), GoalPost.transform.GetChild(1), GoalPost.transform.GetChild(2) }
                .OrderBy(t => Vector3.Angle(direction, Vector3.Normalize(t.transform.position - transform.position)))
                .FirstOrDefault();
                if (!(Vector3.Dot(transform.forward, dirToTarget) > Mathf.Cos((150 / 2) * Mathf.Deg2Rad)))
                {
                    shotdirec = null;
                }
                shot();
            }
            else if (Input.GetKey(KeyCode.S))
            {
                float   horizontal1 = Input.GetAxis("Horizontal");
                float   vertical1   = Input.GetAxis("Vertical");
                Vector3 direction   = new Vector3(horizontal1, 0f, vertical1);
                if (Mathf.Approximately(direction.magnitude, 0f))
                {
                    direction = transform.forward;
                }
                var     targetPlayer = FindPlayerInDirection(direction);
                Vector3 dirToTarget  = (targetPlayer.transform.position - transform.position).normalized;
                if (Vector3.Dot(transform.forward, dirToTarget) > Mathf.Cos((150 / 2) * Mathf.Deg2Rad))
                {
                    pass(targetPlayer, passing.Short);
                }
                else
                {
                    pass(null, passing.Short);
                }
            }
            else if (Input.GetKey(KeyCode.W))
            {
                float   horizontal1 = Input.GetAxis("Horizontal");
                float   vertical1   = Input.GetAxis("Vertical");
                Vector3 direction   = new Vector3(horizontal1, 0f, vertical1);
                if (Mathf.Approximately(direction.magnitude, 0f))
                {
                    direction = transform.forward;
                }
                var     targetPlayer = FindPlayerInDirection(direction);
                Vector3 dirToTarget  = (targetPlayer.transform.position - transform.position).normalized;
                if (Vector3.Dot(transform.forward, dirToTarget) > Mathf.Cos((150 / 2) * Mathf.Deg2Rad))
                {
                    pass(targetPlayer, passing.Tshort);
                }
                else
                {
                    pass(null, passing.Short);
                }
            }
            else if (Input.GetKey(KeyCode.A))
            {
                float   horizontal1 = Input.GetAxis("Horizontal");
                float   vertical1   = Input.GetAxis("Vertical");
                Vector3 direction   = new Vector3(horizontal1, 0f, vertical1);
                if (Mathf.Approximately(direction.magnitude, 0f))
                {
                    direction = transform.forward;
                }
                var     targetPlayer = FindPlayerInDirection(direction);
                Vector3 dirToTarget  = (targetPlayer.transform.position - transform.position).normalized;
                if (Vector3.Dot(transform.forward, dirToTarget) > Mathf.Cos((150 / 2) * Mathf.Deg2Rad))
                {
                    pass(targetPlayer, passing.Long);
                }
                else
                {
                    pass(null, passing.Long);
                }
            }
            else if (Input.GetKey(KeyCode.Q))
            {
                float   horizontal1 = Input.GetAxis("Horizontal");
                float   vertical1   = Input.GetAxis("Vertical");
                Vector3 direction   = new Vector3(horizontal1, 0f, vertical1);
                if (Mathf.Approximately(direction.magnitude, 0f))
                {
                    direction = transform.forward;
                }
                var     targetPlayer = FindPlayerInDirection(direction);
                Vector3 dirToTarget  = (targetPlayer.transform.position - transform.position).normalized;
                if (Vector3.Dot(transform.forward, dirToTarget) > Mathf.Cos((150 / 2) * Mathf.Deg2Rad))
                {
                    pass(targetPlayer, passing.Tlong);
                }
                else
                {
                    pass(null, passing.Long);
                }
            }
        }
        if (HaveBall)
        {
            if (GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("pass"))
            {
                HaveBall = false;
                anim.ResetTrigger("pass");
                if (pag == passing.Short)
                {
                    if (passingTarget != null)
                    {
                        if (Vector3.Distance(transform.position, passingTarget.transform.position) > 25)
                        {
                            Ball.GetComponent <SoccerBall>().spd = 25f;
                        }
                        else
                        {
                            Ball.GetComponent <SoccerBall>().spd = 15f;
                        }

                        backup.transform.position = passingTarget.transform.position;
                        Ball.GetComponent <SoccerBall>().TargetTransform = backup.transform;
                        Ball.GetComponent <SoccerBall>().Target          = passingTarget;
                        Ball.GetComponent <Rigidbody>().AddTorque(transform.root.right * 1500, ForceMode.Impulse);
                    }
                    else
                    {
                        Ball.GetComponent <Rigidbody>().AddForce(transform.forward * 12, ForceMode.Impulse);
                        Ball.GetComponent <Rigidbody>().AddTorque(transform.root.right * 1500, ForceMode.Impulse);
                    }
                }
                else if (pag == passing.Tshort)
                {
                    if (passingTarget != null)
                    {
                        if (Vector3.Distance(transform.position, passingTarget.transform.position) > 25)
                        {
                            Ball.GetComponent <SoccerBall>().spd = 30f;
                        }
                        else
                        {
                            Ball.GetComponent <SoccerBall>().spd = 25f;
                        }

                        backup.transform.position = passingTarget.transform.position + passingTarget.GetComponent <Rigidbody>().velocity *2;
                        Ball.GetComponent <SoccerBall>().TargetTransform = backup.transform;
                        Ball.GetComponent <SoccerBall>().Target          = passingTarget;
                        Ball.GetComponent <Rigidbody>().AddTorque(transform.root.right * 1500, ForceMode.Impulse);
                    }
                    else
                    {
                        Ball.GetComponent <Rigidbody>().AddForce(transform.forward * 20, ForceMode.Impulse);
                        Ball.GetComponent <Rigidbody>().AddTorque(transform.root.right * 1500, ForceMode.Impulse);
                    }
                }
                else if (pag == passing.Long)
                {
                    if (passingTarget != null)
                    {
                        var rigid = GetComponent <Rigidbody>();

                        Vector3 p             = passingTarget.transform.position;
                        float   gravity       = Physics.gravity.magnitude;
                        float   angle         = 45f * Mathf.Deg2Rad;
                        Vector3 planarTarget  = new Vector3(p.x, 0, p.z);
                        Vector3 planarPostion = new Vector3(Ball.transform.position.x, 0, Ball.transform.position.z);
                        float   distance      = Vector3.Distance(planarTarget, planarPostion);
                        float   yOffset       = Ball.transform.position.y - (p.y);
                        if (distance > 35)
                        {
                            yOffset = Ball.transform.position.y - (p.y + 10);
                        }
                        float   initialVelocity     = (1 / Mathf.Cos(angle)) * Mathf.Sqrt((0.5f * gravity * Mathf.Pow(distance, 2)) / (distance * Mathf.Tan(angle) + yOffset));
                        Vector3 velocity            = new Vector3(0, initialVelocity * Mathf.Sin(angle), initialVelocity * Mathf.Cos(angle));
                        float   angleBetweenObjects = Vector3.SignedAngle(planarTarget - planarPostion, Vector3.forward, Vector3.up);
                        Vector3 finalVelocity       = Quaternion.AngleAxis(-angleBetweenObjects, Vector3.up) * velocity;
                        Ball.GetComponent <Rigidbody>().AddForce(finalVelocity * Ball.GetComponent <Rigidbody>().mass, ForceMode.Impulse);
                    }
                    else
                    {
                        Ball.GetComponent <Rigidbody>().AddForce(new Vector3(0, 10f, 0), ForceMode.Impulse);
                        Ball.GetComponent <Rigidbody>().AddForce(transform.forward * 8, ForceMode.Impulse);
                        Ball.GetComponent <Rigidbody>().AddTorque(transform.root.right * 1500, ForceMode.Impulse);
                    }
                }
                else if (pag == passing.Tlong)
                {
                    if (passingTarget != null)
                    {
                        var rigid = GetComponent <Rigidbody>();

                        Vector3 p            = passingTarget.transform.position;
                        float   gravity      = Physics.gravity.magnitude;
                        float   angle        = 50f * Mathf.Deg2Rad;
                        Vector3 planarTarget = new Vector3(p.x, 0, p.z);
                        planarTarget = planarTarget + passingTarget.GetComponent <Rigidbody>().velocity *4.3f;
                        Vector3 planarPostion       = new Vector3(Ball.transform.position.x, 0, Ball.transform.position.z);
                        float   distance            = Vector3.Distance(planarTarget, planarPostion);
                        float   yOffset             = Ball.transform.position.y - (p.y);
                        float   initialVelocity     = (1 / Mathf.Cos(angle)) * Mathf.Sqrt((0.5f * gravity * Mathf.Pow(distance, 2)) / (distance * Mathf.Tan(angle) + yOffset));
                        Vector3 velocity            = new Vector3(0, initialVelocity * Mathf.Sin(angle), initialVelocity * Mathf.Cos(angle));
                        float   angleBetweenObjects = Vector3.SignedAngle(planarTarget - planarPostion, Vector3.forward, Vector3.up);
                        Vector3 finalVelocity       = Quaternion.AngleAxis(-angleBetweenObjects, Vector3.up) * velocity;
                        Ball.GetComponent <Rigidbody>().AddForce(finalVelocity * Ball.GetComponent <Rigidbody>().mass, ForceMode.Impulse);
                    }
                    else
                    {
                        Ball.GetComponent <Rigidbody>().AddForce(new Vector3(0, 10f, 0), ForceMode.Impulse);
                        Ball.GetComponent <Rigidbody>().AddForce(transform.forward * 8, ForceMode.Impulse);
                        Ball.GetComponent <Rigidbody>().AddTorque(transform.root.right * 1500, ForceMode.Impulse);
                    }
                }
            }

            if (GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("shot"))
            {
                HaveBall = false;
                anim.ResetTrigger("shot");
                if (shotdirec != null)
                {
                    Vector3 Direc = (shotdirec.transform.position - transform.position).normalized;
                    transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(Direc.x, Direc.y, Direc.z), 12.0f * Time.deltaTime);
                    Ball.GetComponent <Rigidbody>().AddForce(new Vector3(Direc.x * 33, (Direc.y + 0.2f) * 32, Direc.z * 33), ForceMode.Impulse);
                    Ball.GetComponent <Rigidbody>().AddTorque(transform.root.right * 1500, ForceMode.Impulse);
                }
                else
                {
                    Ball.GetComponent <Rigidbody>().AddForce(new Vector3(transform.forward.x * 32, (transform.forward.y + 0.2f) * 30, transform.forward.z * 32), ForceMode.Impulse);
                    Ball.GetComponent <Rigidbody>().AddTorque(transform.root.right * 1500, ForceMode.Impulse);
                }
            }
        }
    }
Exemplo n.º 14
0
 public void pobur()
 {
     if (this.transform.parent.gameObject.name == "player")
     {
         tet = this.transform.parent.gameObject.GetComponent <hexp> ().lud / 3;
         pp.GetComponent <player> ().army += tet;
         this.transform.parent.gameObject.GetComponent <hexp> ().lud -= tet;
     }
     else if (this.transform.parent.gameObject.name != "hexp(Clone)")
     {
         this.transform.parent.gameObject.GetComponent <hexp> ().ow.GetComponent <ai>().army -= pp.GetComponent <player> ().army;
         pp.GetComponent <player> ().army = 0;
     }
 }