Browse Source

better clouds

master
Josh 2 years ago
parent
commit
ecd3a7fa41
  1. 2
      unity/Assets/Game.cs
  2. 3
      unity/Assets/Prefabs/Cloud.prefab
  3. 11
      unity/Assets/Scripts/Cloud.cs
  4. 7
      unity/Assets/Scripts/CloudWraparound.cs

2
unity/Assets/Game.cs

@ -25,7 +25,7 @@ public class Game : MonoBehaviour
for (int i = 0; i < NUM_CLOUDS; ++i) for (int i = 0; i < NUM_CLOUDS; ++i)
{ {
GameObject cloud = GameObject.Instantiate(_cloudPrefab); GameObject cloud = GameObject.Instantiate(_cloudPrefab);
cloud.transform.position = new Vector3(Random.Range(START_X, START_X + 1920), cloud.transform.position.y, cloud.transform.position.z); cloud.transform.position = new Vector3(Random.Range(START_X, START_X + 1920 + CloudWraparound.DISTANCE_OFF_LEFT_EDGE), cloud.transform.position.y, cloud.transform.position.z);
} }
} }

3
unity/Assets/Prefabs/Cloud.prefab

@ -151,7 +151,7 @@ GameObject:
- component: {fileID: 545282094367413959} - component: {fileID: 545282094367413959}
- component: {fileID: 6161226756571430359} - component: {fileID: 6161226756571430359}
m_Layer: 0 m_Layer: 0
m_Name: hitbox m_Name: rain
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -325,6 +325,7 @@ MonoBehaviour:
_sprites: _sprites:
- {fileID: 21300000, guid: d76eaebf0ab92f444837a89b760938ba, type: 3} - {fileID: 21300000, guid: d76eaebf0ab92f444837a89b760938ba, type: 3}
- {fileID: 21300000, guid: dc9b42400a2750749a98117d1b81e1f1, type: 3} - {fileID: 21300000, guid: dc9b42400a2750749a98117d1b81e1f1, type: 3}
_rain: {fileID: 4636940789921123840}
--- !u!61 &8093627333698608788 --- !u!61 &8093627333698608788
BoxCollider2D: BoxCollider2D:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

11
unity/Assets/Scripts/Cloud.cs

@ -10,6 +10,8 @@ public class Cloud : MonoBehaviour
float _lightningTimeout = 0f; float _lightningTimeout = 0f;
float _timeToRandomStrike; float _timeToRandomStrike;
const bool DO_RANDOM_STRIKES = true; const bool DO_RANDOM_STRIKES = true;
float _timeToFlip = 0f;
[SerializeField] GameObject _rain;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
@ -28,6 +30,13 @@ public class Cloud : MonoBehaviour
_lightningTimeout -= Time.deltaTime; _lightningTimeout -= Time.deltaTime;
_timeToHideLightning -= Time.deltaTime; _timeToHideLightning -= Time.deltaTime;
_timeToRandomStrike -= Time.deltaTime; _timeToRandomStrike -= Time.deltaTime;
_timeToFlip -= Time.deltaTime;
if (_timeToFlip < 0f)
{
_rain.transform.localScale = new Vector3(_rain.transform.localScale.x * -1, _rain.transform.localScale.y, _rain.transform.localScale.z);
_timeToFlip = 0.2f;
}
if (_timeToHideLightning < 0f) if (_timeToHideLightning < 0f)
{ {
@ -55,7 +64,7 @@ public class Cloud : MonoBehaviour
public void ReInit() public void ReInit()
{ {
float scale = Random.Range(1.5f, 2.5f); float scale = Random.Range(1.5f, 2.5f);
float x = Random.Range(-100f, 100f); float x = Random.Range(-200f, 200f);
float y = Random.Range(95f, 975f); float y = Random.Range(95f, 975f);
transform.localScale = new Vector3(scale, scale, 2f); transform.localScale = new Vector3(scale, scale, 2f);
transform.position = new Vector3(transform.position.x + x, y, transform.position.z); transform.position = new Vector3(transform.position.x + x, y, transform.position.z);

7
unity/Assets/Scripts/CloudWraparound.cs

@ -11,6 +11,7 @@ public class CloudWraparound : MonoBehaviour
} }
public const int SCREEN_HEIGHT = 1080; public const int SCREEN_HEIGHT = 1080;
public const int SCREEN_WIDTH = 1920; public const int SCREEN_WIDTH = 1920;
public const float DISTANCE_OFF_LEFT_EDGE = 500f;
// Update is called once per frame // Update is called once per frame
void Update() void Update()
@ -25,10 +26,10 @@ public class CloudWraparound : MonoBehaviour
{ {
this.transform.position = new Vector3(transform.position.x, transform.position.y - SCREEN_HEIGHT, transform.position.z); this.transform.position = new Vector3(transform.position.x, transform.position.y - SCREEN_HEIGHT, transform.position.z);
} }
float DISTANCE_OFF_LEFT_EDGE = -500f;
if (this.transform.position.x < DISTANCE_OFF_LEFT_EDGE) if (this.transform.position.x < DISTANCE_OFF_LEFT_EDGE * -1f)
{ {
this.transform.position = new Vector3(this.transform.position.x + SCREEN_WIDTH + (DISTANCE_OFF_LEFT_EDGE*-1) + 250f, transform.position.y, transform.position.z); this.transform.position = new Vector3(this.transform.position.x + SCREEN_WIDTH + (DISTANCE_OFF_LEFT_EDGE) + 250f, transform.position.y, transform.position.z);
GetComponent<Cloud>().ReInit(); GetComponent<Cloud>().ReInit();
} }

Loading…
Cancel
Save