// Update is called once per frame void Update() { control = (LVL_controler)UInterface.GetComponent(typeof(LVL_controler)); // Vector3 gravityInput; Vector3 nullVector; nullVector.x = 0; nullVector.y = 0; nullVector.z = 0; Rigidbody rigidball; rigidball = gameObject.GetComponent<Rigidbody>(); //Gravity depending on the acceleration ONLY ANDROID //Z = 0 so it does not feel like rolling if (control.gameRunning) { gravityInput = Input.acceleration.normalized; gravityInput.z = 0; Physics.gravity = 20 * gravityInput; if (Fire) { rigidball.AddForce(Physics.gravity * rigidball.mass); } } else rigidball.velocity= nullVector; }
/* The ball may collide with many different objects, some may trigger events */ void OnTriggerEnter(Collider impact) { //Case 1: BALL collided with an object that will kill if (impact.tag == "KillObject") { nLVL = (LVL_controler)UInterface.GetComponent(typeof(LVL_controler)); nLVL.DeathPenalty(); Respawn(); print("Ball killed"); } /* Detect that the ball has gone into the cave */ if (impact.name == "CaveIn") { GameObject[] frontCave; frontCave = GameObject.FindGameObjectsWithTag("FrontCave"); for (int i = 0; i < frontCave.Length; i++) { frontCave[i].GetComponent<Renderer>().enabled = false; } print("Ball in the cave"); } /* Detect that the ball has gone OUT of the cave */ if (impact.name == "CaveOut") { GameObject[] frontCave; frontCave = GameObject.FindGameObjectsWithTag("FrontCave"); for (int i = 0; i < frontCave.Length; i++) { //print(frontCave[i].name); frontCave[i].GetComponent<Renderer>().enabled = true; } print("Ball Out the cave"); } /* The Ball has hit the win condition */ if (impact.transform.gameObject.tag == "WinCondition") { nLVL = (LVL_controler)UInterface.GetComponent(typeof(LVL_controler)); nLVL.GoalReached(); print("Level Passed"); //Debug info } }