Lamp.Update C# (CSharp) Method

Update() private method

private Update ( ) : void
return void
	void Update () {
		if (canFade)
		{
			if (fadeIn)
			{
				canvasGroup.alpha += Time.deltaTime;
				if (canvasGroup.alpha > 1)
					canFade = false;
			}
			else
			{
				canvasGroup.alpha -= Time.deltaTime;
				if (canvasGroup.alpha < 0)
					canFade = false;
			}
		}
		
		if (Input.GetKeyDown("e"))
		{
			if(canUse)
			{
				if (switchState)
				{
					lights.SetActive(false);
					switchState = false;
					instruction.text = "       Press E to\nbrighten the lights";
					audioToPlay.clip = off;
					audioToPlay.Play();
				}
				else
				{
					lights.SetActive(true);
					switchState = true;
					instruction.text = "       Press E to\n    dim the lights";
					audioToPlay.clip = on;
					audioToPlay.Play();
				}
			}
		}
	}
	

Usage Example

        public override void Update(GameTime gameTime)
        {
            foreach (var room in Rooms)
            {
                room.Update(gameTime);
                Boolean playerInRoom = false;
                if (room.IsInRoom(Player.NewPosition))
                {
                    Player.Update(gameTime);

                    var collidedWall = room.CollidesWithWall(Player.BottomVertex, Player.UpVertex);
                    if (!Game.godMode)
                    {
                        Player.CollidedWith(collidedWall);
                    }
                    room.CheckCollectiblesCollision(Player);
                    room.CheckObstacleCollision(Player);
                    playerInRoom = true;
                }

                var bullets = Bullets.FindAll(bullet => room.IsInRoom(bullet.BottomVertex) || room.IsInRoom(bullet.UpVertex));
                var enemies = Array.FindAll(Enemies, enemy => room.IsInRoom(enemy.Position));
                bullets.ForEach(b => b.Update(gameTime));
                foreach (var enemy in enemies)
                {
                    enemy.Update(gameTime);
                    var collidedWall = room.CollidesWithWall(enemy.BottomVertex, enemy.UpVertex);
                    if (!(collidedWall is null))
                    {
                        enemy.CollidedWith(collidedWall);
                    }
                    room.CheckObstacleCollision(enemy);
                    if (playerInRoom && Player.CollidesWith(enemy.BottomVertex, enemy.UpVertex) && !Game.godMode)
                    {
                        enemy.CollidedWith(Player);
                    }
                    var collidedBullets = bullets.FindAll(bullets => bullets.CollidesWith(enemy.BottomVertex, enemy.UpVertex));
                    collidedBullets.ForEach(b => b.CollidedWith(enemy));
                }
                bullets.FindAll(b => room.CollidesWithWall(b.BottomVertex, b.UpVertex) != null).ForEach(b => b.CollidedWith());
                bullets.ForEach(b => room.CheckObstacleCollision(b));
            }
            Lamp.Update(gameTime);
            Lamp2.Update(gameTime);
        }