Skip to content

Commit cea74fe

Browse files
committed
Scripts Update
0 parents  commit cea74fe

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

DayAndNight.cs

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class DayAndNight : MonoBehaviour
6+
{
7+
[Range(0, 1)]
8+
public float time;
9+
public float fullDayLength;
10+
public float startTime = 0.4f;
11+
public float timeRate;
12+
public Vector3 noon;
13+
14+
[Header("Sun")]
15+
public Light sun;
16+
public Gradient sunColor;
17+
public AnimationCurve sunIntensity;
18+
19+
[Header("Moon")]
20+
public Light moon;
21+
public Gradient moonColor;
22+
public AnimationCurve moonIntensity;
23+
24+
[Header("Other Seetings")]
25+
public AnimationCurve lightingIntensityMultiplier;
26+
public AnimationCurve reflectionIntensityMultiplier;
27+
28+
public Material day;
29+
public Material night;
30+
31+
float duration = 2.0f;
32+
33+
34+
// Start is called before the first frame update
35+
void Start()
36+
{
37+
timeRate = 1 / fullDayLength;
38+
time = startTime;
39+
}
40+
41+
// Update is called once per frame
42+
void Update()
43+
{
44+
time += timeRate * Time.deltaTime;
45+
46+
if (time >= 1)
47+
time = 0;
48+
49+
sun.transform.eulerAngles = (time - 0.25f) * noon * 4.0f;
50+
moon.transform.eulerAngles = (time - 0.75f) * noon * 4.0f;
51+
52+
sun.intensity = sunIntensity.Evaluate(time);
53+
moon.intensity = moonIntensity.Evaluate(time);
54+
55+
sun.color = sunColor.Evaluate(time);
56+
moon.color = moonColor.Evaluate(time);
57+
58+
if(sun.intensity == 0 && sun.gameObject.activeInHierarchy)
59+
{
60+
sun.gameObject.SetActive(false);
61+
}
62+
else if(sun.intensity > 0 && !sun.gameObject.activeInHierarchy)
63+
{
64+
sun.gameObject.SetActive(true);
65+
}
66+
67+
if (moon.intensity == 0 && moon.gameObject.activeInHierarchy)
68+
{
69+
moon.gameObject.SetActive(false);
70+
}
71+
else if (moon.intensity > 0 && !moon.gameObject.activeInHierarchy)
72+
{
73+
moon.gameObject.SetActive(true);
74+
}
75+
76+
RenderSettings.ambientIntensity = lightingIntensityMultiplier.Evaluate(time);
77+
RenderSettings.reflectionIntensity = reflectionIntensityMultiplier.Evaluate(time);
78+
}
79+
}

ItemDrop.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class ItemDrop : MonoBehaviour
6+
{
7+
public health hp;
8+
public bool droped;
9+
public GameObject[] Dropable;
10+
// Start is called before the first frame update
11+
void Start()
12+
{
13+
14+
}
15+
16+
// Update is called once per frame
17+
void Update()
18+
{
19+
if(hp.dead && !droped)
20+
{
21+
Drop();
22+
}
23+
}
24+
25+
public void Drop()
26+
{
27+
28+
for(int i = 0; i < Dropable.Length; i++)
29+
{
30+
GameObject item = Instantiate(Dropable[i], transform.position, Quaternion.identity, null);
31+
}
32+
33+
droped = true;
34+
}
35+
}

0 commit comments

Comments
 (0)