private void Start() { // Check if the script is attached to a Camera _camera = gameObject.GetComponent <Camera>(); if (_camera == null) { Debug.LogError(string.Format("The {0} script can only be attached to the Camera!", GetType()), transform); Destroy(this); return; } // Adding Rigidbody and Collider required for receiving trigger events Rigidbody tempRigidbody = gameObject.GetComponent <Rigidbody>(); if (tempRigidbody == null) { tempRigidbody = gameObject.AddComponent <Rigidbody>(); tempRigidbody.isKinematic = true; tempRigidbody.useGravity = false; } else { Debug.LogWarning("Rigidbody component is already attached to this camera, unexpected behaviour may occur", transform); } Collider tempCollider = gameObject.GetComponent <Collider>(); if (tempCollider == null) { tempCollider = gameObject.AddComponent <BoxCollider>(); tempCollider.isTrigger = true; ((BoxCollider)tempCollider).size = Vector3.zero; } else { Debug.LogWarning("Collider already attached to this camera, unexpected behaviour may occur", transform); } _waterDetector = GetComponent <WaterDetector>() ?? gameObject.AddComponent <WaterDetector>(); // Reading the initial fog state _defaultFog = RenderSettings.fog; _defaultFogMode = RenderSettings.fogMode; _defaultFogColor = RenderSettings.fogColor; _defaultFogDensity = RenderSettings.fogDensity; _defaultFogStartDistance = RenderSettings.fogStartDistance; _defaultFogEndDistance = RenderSettings.fogEndDistance; _defaultSkybox = RenderSettings.skybox; }
private void Start() { // Check if the script is attached to a Camera _camera = gameObject.GetComponent<Camera>(); if (_camera == null) { Debug.LogError(string.Format("The {0} script can only be attached to the Camera!", GetType()), transform); Destroy(this); return; } // Adding Rigidbody and Collider required for receiving trigger events Rigidbody tempRigidbody = gameObject.GetComponent<Rigidbody>(); if (tempRigidbody == null) { tempRigidbody = gameObject.AddComponent<Rigidbody>(); tempRigidbody.isKinematic = true; tempRigidbody.useGravity = false; } else { Debug.LogWarning("Rigidbody component is already attached to this camera, unexpected behaviour may occur", transform); } Collider tempCollider = gameObject.GetComponent<Collider>(); if (tempCollider == null) { tempCollider = gameObject.AddComponent<BoxCollider>(); tempCollider.isTrigger = true; ((BoxCollider) tempCollider).size = Vector3.zero; } else { Debug.LogWarning("Collider already attached to this camera, unexpected behaviour may occur", transform); } _waterDetector = GetComponent<WaterDetector>() ?? gameObject.AddComponent<WaterDetector>(); // Reading the initial fog state _defaultFog = RenderSettings.fog; _defaultFogMode = RenderSettings.fogMode; _defaultFogColor = RenderSettings.fogColor; _defaultFogDensity = RenderSettings.fogDensity; _defaultFogStartDistance = RenderSettings.fogStartDistance; _defaultFogEndDistance = RenderSettings.fogEndDistance; _defaultSkybox = RenderSettings.skybox; }