Пример #1
0
 void OnControllerColliderHit(ControllerColliderHit hit)
 {
     if (hit.collider.tag == "Player")
     {
         Vector3 pushDir = hit.transform.position - transform.position;
         pushDir  *= pushSpeed;
         pushDir.y = 10.5f;
         // This should allow us to interact with this script directly and define an appropriate behaviour that way
         MinifigControllerWTH hitCharacterController = hit.collider.GetComponentInParent <MinifigControllerWTH>();
         hitCharacterController.AddForce(pushDir);
     }
     if (hit.collider.tag == "floor")
     {
         Respawn();
     }
     if (hit.collider.tag == "Credit")
     {
         GameObject credit = hit.gameObject;
         AddPoints(1);
         Destroy(credit);
     }
     if (controller.isGrounded)
     {
         RaycastHit raycastHit;
         if (Physics.SphereCast(transform.position + Vector3.up * 0.8f, 0.8f, Vector3.down, out raycastHit, 0.1f, -1, QueryTriggerInteraction.Ignore))
         {
             groundedTransform     = raycastHit.collider.transform;
             oldGroundedPosition   = raycastHit.point;
             groundedLocalPosition = groundedTransform.InverseTransformPoint(oldGroundedPosition);
             oldGroundedRotation   = groundedTransform.rotation;
         }
     }
 }
Пример #2
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     player           = animator.gameObject;
     playerController = animator.GetComponentInParent <MinifigControllerWTH>();
     pickUpContainer  = GameObject.Find("PowerUpSpawner");
     target           = powerUpInRange(player.transform.position);
 }
Пример #3
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Player")
     {
         MinifigControllerWTH controller = other.gameObject.GetComponent <MinifigControllerWTH>();
         controller.AddPowerUp(powerUp);
         Destroy(this.gameObject);
     }
 }
Пример #4
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         MinifigControllerWTH controller = collision.gameObject.GetComponent <MinifigControllerWTH>();
         Vector3 bounce = new Vector3(0, bounciness, 0);
         controller.AddForce(bounce);
     }
 }
Пример #5
0
    void Update()
    {
        //If your game has already ended you can call the MiniGameFinished method
        if (myGameEndingCondition == true)
        {
            List <Tuple <int, int> > placements = new List <Tuple <int, int> >();

            //Create array of positions with player ids, this also works in case there are multiple players in one position
            for (int i = 0; i < Players.Count; i++)
            {
                MinifigControllerWTH controller = Players[i].GetComponent <MinifigControllerWTH>();
                placements.Add(new Tuple <int, int>(i, controller.playerPoints));
            }
            placements.Sort((tuple1, tuple2) =>
            {
                if (tuple1.Item2 > tuple2.Item2)
                {
                    return(1);
                }
                else if (tuple1.Item2 == tuple2.Item2)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            });
            List <List <int> > results = new List <List <int> >();
            int lastValue = 0;
            placements.ForEach(tuple => {
                if (results.Count != 0 && lastValue == tuple.Item2)
                {
                    results[results.Count - 1].Add(tuple.Item1);
                }
                else
                {
                    results.Add(new List <int>()
                    {
                        tuple.Item1
                    });
                    lastValue = tuple.Item2;
                }
            });
            while (results.Count < 4)
            {
                results.Add(new List <int>());
            }

            Debug.Log($"Erster {results[0].ToArray()}, Zweiter {results[1].ToArray()}, Dritter {results[2].ToArray()}, Vierter {results[3].ToArray()}");

            //Note this is still work in progress, but ideally you will use it like this
            MiniGameFinished(firstPlace: results[0].ToArray(), secondPlace: results[1].ToArray(), thirdPlace: results[2].ToArray(), fourthPlace: results[3].ToArray());
        }
        myGameEndingCondition = false;
    }
Пример #6
0
    public GameObject SpawnPlayerEquipment(string powerUpIdentifier, MinifigControllerWTH player)
    {
        string path = @"Minifig Character/jointScaleOffset_grp/Joint_grp/detachSpine/spine01/spine02/spine03/spine04/spine05/spine06/shoulder_R/armUp_R/arm_R/wristTwist_R/wrist_R/hand_R/BatSnap";
        //Transform batLock = player.transform.Find(path);
        GameObject powerUpPrefab = spawnablePowerUps.Find(prefab => prefab.name == powerUpIdentifier);
        GameObject bat           = Instantiate(powerUpPrefab);

        bat.transform.SetParent(player.transform.Find(path), false);
        return(bat);
    }
Пример #7
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     game             = GameObject.Find("WTHGameManger").GetComponent <WhatTheHillGame>();
     player           = animator.gameObject;
     playerController = animator.GetComponentInParent <MinifigControllerWTH>();
     targetPlayer     = playerInRange(player.transform.position);
     if (targetPlayer == null)
     {
         animator.SetBool("PlayerInSight", false);
     }
 }
Пример #8
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        playerController = animator.GetComponentInParent <MinifigControllerWTH>();
        player           = animator.gameObject;
        this.animator    = animator;

        game            = GameObject.Find("WTHGameManger").GetComponent <WhatTheHillGame>();
        pickUpContainer = GameObject.Find("PowerUpSpawner");
        ringMoveArrows  = GameObject.Find("RingMoveArrows");
        foreach (Transform arrow in ringMoveArrows.transform)
        {
            goals.Add(arrow.position);
        }
    }
Пример #9
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         GameObject           collidedPlayer = collision.gameObject;
         MinifigControllerWTH controller     = collidedPlayer.GetComponent <MinifigControllerWTH>();
         if (!(controller == this.gameObject.GetComponentInParent <MinifigControllerWTH>()))
         {
             Vector3 pushDir = collidedPlayer.transform.position - transform.position;
             pushDir  *= batPower;
             pushDir.y = homerunHeight;
             controller.AddForce(pushDir);
             Debug.Log("Schläger hat Spieler getroffen. Spieler fliegt richtung " + pushDir.ToString());
         }
     }
 }
Пример #10
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        playerController = animator.GetComponentInParent <MinifigControllerWTH>();
        player           = animator.gameObject;
        this.animator    = animator;

        game            = GameObject.Find("WTHGameManger").GetComponent <WhatTheHillGame>();
        pickUpContainer = GameObject.Find("PowerUpSpawner");

        Vector3 targetPosition = new Vector3(0, 0, 0);

        currentPath = new NavMeshPath();
        NavMesh.CalculatePath(player.transform.position, targetPosition, NavMesh.AllAreas, currentPath);
        for (int i = 0; i < currentPath.corners.Length - 1; i++)
        {
            Debug.DrawLine(currentPath.corners[i], currentPath.corners[i + 1], Color.red);
        }
    }
Пример #11
0
 // Start is called before the first frame update
 void Start()
 {
     controller = player.GetComponent <MinifigControllerWTH>();
 }