我正在为我的游戏组合一个日夜系统,我有一个脚本让这一天正常进行不要过夜,我想创建另一个副本并在晚上放入相同的脚本然后第一个脚本调用第二个脚本,第二个脚本调用第一个井是一个无休止的白天和黑夜周期,想知道是否有人有任何想法让它变得更好或者是编程世界的新手所以我不知道如何做到这一点。
对不起我的英语我想改进,我是巴西人。我感谢所有的帮助,等待某人的回复。
var slider : float;
var slider2 : float;
var Hour : float;
private var Tod: float;
var sun: Light;
var NightFogColor : Color;
var DuskFogColor : Color;
var MorningFogColor : Color;
var MiddayFogColor : Color;
var NightAmbientLight : Color;
var DuskAmbientLight : Color;
var MorningAmbientLight : Color;
var MiddayAmbientLight : Color;
var NightTint : Color;
var DuskTint : Color;
var MorningTint : Color;
var MiddayTint : Color;
var SkyBoxMaterial1 : Material;
var SkyBoxMaterial2 : Material;
var SunNight : Color;
var SunDay : Color;
function OnGUI () {
slider= GUI.HorizontalSlider( Rect(20,20,200,30), slider, 0,1.0);
Hour= slider*24;
Tod= slider2*24;
sun.transform.localEulerAngles.x= (slider*360)-90;
slider = slider +Time.deltaTime/900;
sun.color = Color.Lerp (SunNight, SunDay, slider*2);
if(slider<0.5){
slider2= slider;
}
if(slider>0.5){
slider2= (1-slider);
}
sun.intensity = (slider2-0.2)*2;
if(Tod<4){
//it is Night
RenderSettings.skybox=SkyBoxMaterial1;
RenderSettings.skybox.SetFloat("_Blend", 0);
SkyBoxMaterial1.SetColor ("_Tint", NightTint);
RenderSettings.ambientLight = NightAmbientLight;
RenderSettings.fogColor = NightFogColor;
}
if(Tod>4&&Tod<6){
RenderSettings.skybox=SkyBoxMaterial1;
RenderSettings.skybox.SetFloat("_Blend", 0);
RenderSettings.skybox.SetFloat("_Blend", (Tod/2)-2);
SkyBoxMaterial1.SetColor ("_Tint", Color.Lerp (NightTint, DuskTint, (Tod/2)-2) );
RenderSettings.ambientLight = Color.Lerp (NightAmbientLight, DuskAmbientLight, (Tod/2)-2);
RenderSettings.fogColor = Color.Lerp (NightFogColor,DuskFogColor, (Tod/2)-2);
//it is Dusk
}
if(Tod>6&&Tod<8){
RenderSettings.skybox=SkyBoxMaterial2;
RenderSettings.skybox.SetFloat("_Blend", 0);
RenderSettings.skybox.SetFloat("_Blend", (Tod/2)-3);
SkyBoxMaterial2.SetColor ("_Tint", Color.Lerp (DuskTint,MorningTint, (Tod/2)-3) );
RenderSettings.ambientLight = Color.Lerp (DuskAmbientLight, MorningAmbientLight, (Tod/2)-3);
RenderSettings.fogColor = Color.Lerp (DuskFogColor,MorningFogColor, (Tod/2)-3);
//it is Morning
}
if(Tod>8&&Tod<10){
RenderSettings.ambientLight = MiddayAmbientLight;
RenderSettings.skybox=SkyBoxMaterial2;
RenderSettings.skybox.SetFloat("_Blend", 1);
SkyBoxMaterial2.SetColor ("_Tint", Color.Lerp (MorningTint,MiddayTint, (Tod/2)-4) );
RenderSettings.ambientLight = Color.Lerp (MorningAmbientLight, MiddayAmbientLight, (Tod/2)-4);
RenderSettings.fogColor = Color.Lerp (MorningFogColor,MiddayFogColor, (Tod/2)-4);
}
}
//it is getting Midday
答案 0 :(得分:0)
如果您只是在寻找激活和停用脚本的代码,您可以这样做。
假设两个脚本都在同一个对象中
GetComponent(scriptName).enabled = true; (或拒绝拒绝)