// Use this for initialization void Start() { crumbleState = CrumbleState.SAFE; switch (type) { case 0: crumbleType = CrumbleType.CONSTANT; break; case 1: crumbleType = CrumbleType.ONOFF; break; case 2: crumbleType = CrumbleType.RESPAWN; break; default: crumbleType = CrumbleType.ONOFF; break; } //BlueScale provides the scale to multiply timer by to provide the new blue value blueScale = blueValue / timer; //Set the base color gameObject.renderer.material.color = new Color(0, 0, blueValue); timerMax = timer; respawnTimerMax = respawnTimer; }
void OnTriggerEnter(Collider other) { if (other.tag == "Player") { crumbleState = CrumbleState.CRUMBLING; } }
// Use this for initialization void Start() { crumbleState = CrumbleState.SAFE; switch (type) { case 0: crumbleType = CrumbleType.CONSTANT; break; case 1: crumbleType = CrumbleType.ONOFF; break; case 2: crumbleType = CrumbleType.RESPAWN; break; default: crumbleType = CrumbleType.ONOFF; break; } //BlueScale provides the scale to multiply timer by to provide the new blue value blueScale = blueValue / timer; //Set the color to the original's color origB = gameObject.renderer.material.color.b; origG = gameObject.renderer.material.color.g; origR = gameObject.renderer.material.color.r; timerMax = timer; respawnTimerMax = respawnTimer; }
// Update is called once per frame void Update() { if (crumbleState == CrumbleState.CRUMBLING) { UpdateCrumbling(); } else if (crumbleState == CrumbleState.SAFE) { UpdateSafe(); } //Change colors based on state blueValue = timer * blueScale; gameObject.renderer.material.color = new Color(origR, origG, origB, blueValue); /* Old method * if (crumbleType == CrumbleType.CONSTANT) { * gameObject.renderer.material.color = new Color(0, 0, blueValue); * } else if (crumbleType == CrumbleType.ONOFF) { * gameObject.renderer.material.color = new Color(0, blueValue, blueValue); * } else if (crumbleType == CrumbleType.RESPAWN) { * gameObject.renderer.material.color = new Color(blueValue, blueValue, 0); * } */ if (timer <= 0) { //audio.PlayOneShot(snapSound,1); renderer.enabled = false; collider.enabled = false; gameObject.transform.collider.enabled = false; //Disable sibling renderers transform.parent.Find("Edges_Cylinder_Material.005").transform.renderer.enabled = false; Debug.Log(transform.parent.Find("Edges_Cylinder_Material.005").name); transform.parent.Find("Sphere_Sphere_Material.006").transform.renderer.enabled = false; transform.parent.collider.enabled = false; crumbleState = CrumbleState.SAFE; if (crumbleType == CrumbleType.RESPAWN) { respawnTimer -= Time.deltaTime; if (respawnTimer <= 0) { renderer.enabled = true; collider.enabled = true; transform.parent.Find("Edges_Cylinder_Material.005").transform.renderer.enabled = true; transform.parent.Find("Sphere_Sphere_Material.006").transform.renderer.enabled = true; transform.parent.collider.enabled = true; timer = timerMax; respawnTimer = respawnTimerMax; } } } }
// Update is called once per frame void Update() { if (crumbleState == CrumbleState.CRUMBLING) { UpdateCrumbling(); } else if (crumbleState == CrumbleState.SAFE) { UpdateSafe(); } //Change colors based on state blueValue = timer * blueScale; if (crumbleType == CrumbleType.CONSTANT) { gameObject.renderer.material.color = new Color(0, 0, blueValue); } else if (crumbleType == CrumbleType.ONOFF) { gameObject.renderer.material.color = new Color(0, blueValue, blueValue); } else if (crumbleType == CrumbleType.RESPAWN) { gameObject.renderer.material.color = new Color(blueValue, blueValue, 0); } if (timer <= 0) { //audio.PlayOneShot(snapSound,1); renderer.enabled = false; collider.enabled = false; crumbleState = CrumbleState.SAFE; if (crumbleType == CrumbleType.RESPAWN) { respawnTimer -= Time.deltaTime; if (respawnTimer <= 0) { renderer.enabled = true; collider.enabled = true; timer = timerMax; respawnTimer = respawnTimerMax; } } } }
void OnTriggerExit(Collider other) { if (other.tag == "Player") { if (crumbleType == CrumbleType.CONSTANT) { //Do nothing. Keeps crumbling. } if (crumbleType == CrumbleType.ONOFF) { crumbleState = CrumbleState.SAFE; } if (crumbleType == CrumbleType.RESPAWN) { //crumbleState = CrumbleState.SAFE; } } }