Skip to content

Commit 44a9df7

Browse files
committedMar 22, 2022
upgrade to 2019.4.25f1, add BreakOnCollision script (to break object when it falls/hits something), adjust scripts to reduce GC, fix object rotation, add copy rigidbody properties (velocity, angular, mass, usegravity), add namespace, add 2nd example texture
1 parent c974025 commit 44a9df7

25 files changed

+1016
-245
lines changed
 

‎.vsconfig

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": "1.0",
3+
"components": [
4+
"Microsoft.VisualStudio.Workload.ManagedGame"
5+
]
6+
}

‎Assets/Materials/UV_Debug.mat

4.16 KB
Binary file not shown.

‎Assets/Materials/UV_Debug.mat.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
2.46 KB
Binary file not shown.

‎Assets/Resources.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Assets/Resources/BillingMode.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"androidStore":"GooglePlay"}

‎Assets/Resources/BillingMode.json.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
9.14 KB
Binary file not shown.

‎Assets/Scripts/BreakOnCollision.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using Unitycoder.Demos;
4+
using UnityEngine;
5+
6+
namespace Unitycoder.Demos
7+
{
8+
public class BreakOnCollision : MonoBehaviour
9+
{
10+
[Tooltip("Collision impact threshold")]
11+
public float breakForce = 10f;
12+
13+
private void OnCollisionEnter(Collision collision)
14+
{
15+
if (collision.relativeVelocity.magnitude > breakForce)
16+
{
17+
// NOTE this can cause pieces to fly too much..
18+
SimpleMeshExploder.instance.Explode(transform);
19+
}
20+
}
21+
}
22+
}

‎Assets/Scripts/BreakOnCollision.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Assets/Scripts/BuildScene.cs

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
// instantiate stack of boxes
22
using UnityEngine;
33

4-
public class BuildScene : MonoBehaviour
4+
namespace Unitycoder.Demos
55
{
6-
public Transform prefab;
7-
8-
public int width = 3;
9-
public int heigth = 3;
10-
public int depth = 3;
11-
12-
void Start()
6+
public class BuildScene : MonoBehaviour
137
{
14-
Vector3 pos = Vector3.zero;
15-
Vector3 o = prefab.GetComponent<Renderer>().bounds.size + new Vector3(0.03f, 0.03f, 0.03f);
8+
public Transform prefab;
9+
10+
public int width = 3;
11+
public int heigth = 3;
12+
public int depth = 3;
1613

17-
for (int x = 0; x < width; x++)
14+
void Start()
1815
{
19-
for (int y = 0; y < heigth; y++)
16+
Vector3 pos = Vector3.zero;
17+
Vector3 o = prefab.GetComponent<Renderer>().bounds.size + new Vector3(0.03f, 0.03f, 0.03f);
18+
19+
for (int x = 0; x < width; x++)
2020
{
21-
for (int z = 0; z < depth; z++)
21+
for (int y = 0; y < heigth; y++)
2222
{
23-
pos = new Vector3(x * o.x, y * o.y, z * o.z);
24-
Instantiate(prefab, pos, Quaternion.identity);
23+
for (int z = 0; z < depth; z++)
24+
{
25+
pos = new Vector3(x * o.x, y * o.y, z * o.z);
26+
Instantiate(prefab, pos, Quaternion.identity);
27+
}
2528
}
2629
}
27-
}
2830

31+
}
2932
}
30-
}
33+
}

‎Assets/Scripts/MeshFader.cs

+24-21
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,38 @@
33
using UnityEngine;
44
using System.Collections;
55

6-
public class MeshFader : MonoBehaviour
6+
namespace Unitycoder.Demos
77
{
8-
private bool fadeOut = false;
9-
10-
void Update()
8+
public class MeshFader : MonoBehaviour
119
{
12-
if (fadeOut) return;
10+
private bool fadeOut = false;
1311

14-
// wait until rigibody is spleeping
15-
if (GetComponent<Rigidbody>().IsSleeping())
12+
void Update()
1613
{
17-
fadeOut = true;
18-
StartCoroutine(FadeOut());
14+
if (fadeOut) return;
15+
16+
// wait until rigibody is spleeping
17+
if (GetComponent<Rigidbody>().IsSleeping())
18+
{
19+
fadeOut = true;
20+
StartCoroutine(FadeOut());
21+
}
1922
}
20-
}
2123

22-
IEnumerator FadeOut()
23-
{
24-
float fadeTime = 2.0f;
25-
var rend = GetComponent<Renderer>();
24+
IEnumerator FadeOut()
25+
{
26+
float fadeTime = 2.0f;
27+
var rend = GetComponent<Renderer>();
2628

27-
var startColor = Color.white;
28-
var endColor = new Color(1, 1, 1, 0);
29+
var startColor = Color.white;
30+
var endColor = new Color(1, 1, 1, 0);
2931

30-
for (float t = 0.0f; t < fadeTime; t += Time.deltaTime)
31-
{
32-
rend.material.color = Color.Lerp(startColor, endColor, t / fadeTime);
33-
yield return null;
32+
for (float t = 0.0f; t < fadeTime; t += Time.deltaTime)
33+
{
34+
rend.material.color = Color.Lerp(startColor, endColor, t / fadeTime);
35+
yield return null;
36+
}
37+
Destroy(gameObject);
3438
}
35-
Destroy(gameObject);
3639
}
3740
}

0 commit comments

Comments
 (0)
Please sign in to comment.