Hello guys,
I’ve run into a problem and am hoping that some of you guys might be able to help w/ Unity 4.6.3f.
The question revolves around this: I found a tut on Youtube about adding a fog effect in the water and it worked fine. However, it used a script on the “Main Camera” and had waterLevel variable meaning it was unusable for water at different heights and/or lows. So, I decided to try and make the a new JavaScript function and make the code work of a isTrigger collider. It did work fine on the “Dam” object. Then I tried using basically the same code with minor differences for checking purposes to work on a higher level, a “River” object and I couldn’t get it to work at all. Playing around with the objects I found I could have on one or the other but not both.
So, I am hoping that you make be able to tell me what changes I would need to make to the code to get it working on both objects.
Thankyou so much for your time.
The JS code is below:
#pragma strict
//not needed here - should remove
var callObject: GameObject;
//set water level - not used anymore
private var waterLevel: float;
//use a boolean value to stipulate whether the controller is underWater
private var isUnder: boolean;
// have colours/vars to change appearance when in water
//basically just changing the fog appearance
//this sets fog to around about normal
var normColour = new Color (0.5f, 0.5f, 0.5f, 0.5f);
//this sets fog much deeper
//var underDamColour = new Color (0.99f, 0.01f, 0.01f, 0.01f); //deep red veery cool :)
private var underDamColour = new Color (0.22f, 0.65f, 0.77f, 0.5f);
function OnTriggerEnter(object : Collider){
//Quick and nasty
print("Dam Collider entered ...........");
isUnder = true;
//callObject.SendMessage("callFunction");
}
function OnTriggerExit(object : Collider){
//Quick and nasty
print("Dam collider exited ...........");
isUnder=false;
RenderSettings.fog = false;
}
function callFunction(){
print("function called............................................");
//no longer used
}//-->End callFunction
function FixedUpdate(){
//print("FixedUpdate..");
//call function according to isUnder value
if(isUnder) SetUnderDam();
if(!isUnder) SetNorm();
}//-->end FixedUpdate()
//changer Render Setting for on land :)
function SetNorm(){
RenderSettings.fogColor = normColour;
RenderSettings.fogDensity = 0.002f;
//stop the caustic generator from making those weird caustics on the land
GameObject.Find("Caustics Projector").GetComponent(Projector).enabled = false;
}//-->end SetUnder()
//change Render Setting for underwater
function SetUnderDam(){
//print("Under");
RenderSettings.fogColor = underDamColour;
//far to thick to see anything
//RenderSettings.fogDensity = 0.99f;
RenderSettings.fogDensity = 0.05f;
RenderSettings.fog = true;
//make the weird caustics appear in the water
GameObject.Find("Caustics Projector").GetComponent(Projector).enabled = true;
}//-->end SetUnder()