void Start() { fileNum = PlayerPrefs.GetInt("SaveFile"); rb = GetComponent<Rigidbody>(); mor = ShapeVar.SPHERE; // Set the animator for the top and other related fields: m_animator = GetComponent<Animator>(); m_animator.enabled = false; spinning = false; haveItem = false; // Set the text for the current attempt. SetAttemptText(); // Set the slider to be invisible at the start (so it only shows for the cylinder) chargeSlider.gameObject.SetActive(false); startTime = Time.time; levelWon = false; gameObject.transform.position = spawn.transform.position; }
void updateShape() { //Explosion effect for morphing var exp = GetComponent<ParticleSystem>(); //currentCollisions = new List<GameObject>(); if (shrunk && mor != ShapeVar.CUBE) { this.shrink(false); } ShapeVar next = ShapeVar.NONE; if (Input.GetKeyDown(KeyCode.Alpha1) && mor != ShapeVar.SPHERE) next = ShapeVar.SPHERE; if (Input.GetKeyDown(KeyCode.Alpha2) && mor != ShapeVar.CYLINDER && levelManager.GetCurrentLevel() >= 2) next = ShapeVar.CYLINDER; if (Input.GetKeyDown(KeyCode.Alpha3) && mor != ShapeVar.CUBE && levelManager.GetCurrentLevel() >= 3) next = ShapeVar.CUBE; if (Input.GetKeyDown(KeyCode.Alpha4) && mor != ShapeVar.TOP && levelManager.GetCurrentLevel() >= 4) next = ShapeVar.TOP; if (next != ShapeVar.NONE) { exp.Play(); if (mor == ShapeVar.SPHERE) GetComponent<SphereCollider>().enabled = false; else if (mor == ShapeVar.CYLINDER) GetComponent<MeshCollider>().enabled = false; else if (mor == ShapeVar.CUBE) GetComponent<BoxCollider>().enabled = false; else if (mor == ShapeVar.TOP) GetComponent<MeshCollider>().enabled = false; if (next == ShapeVar.SPHERE) { GetComponent<SphereCollider>().enabled = true; GetComponent<MeshFilter>().mesh = sphere; chargeSlider.gameObject.SetActive(false); spinning = false; speed = 80; m_animator.enabled = false; rb.collisionDetectionMode = CollisionDetectionMode.Discrete; mor = ShapeVar.SPHERE; } else if (next == ShapeVar.CYLINDER) { GetComponent<MeshCollider>().sharedMesh = cylinder; GetComponent<MeshCollider>().enabled = true; GetComponent<MeshFilter>().mesh = cylinder; chargeSlider.gameObject.SetActive(true); spinning = false; m_animator.enabled = false; speed = 240; rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; mor = ShapeVar.CYLINDER; } else if (next == ShapeVar.CUBE) { GetComponent<BoxCollider>().enabled = true; GetComponent<MeshFilter>().mesh = cube; chargeSlider.gameObject.SetActive(false); spinning = false; speed = 80; m_animator.enabled = false; rb.collisionDetectionMode = CollisionDetectionMode.Discrete; mor = ShapeVar.CUBE; } else if (next == ShapeVar.TOP) { // Need to change the mesh collider mesh to be top instead of cylinder. GetComponent<MeshCollider>().sharedMesh = top; GetComponent<MeshCollider>().enabled = true; GetComponent<MeshFilter>().mesh = top; chargeSlider.gameObject.SetActive(false); speed = 80; rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; mor = ShapeVar.TOP; } } }