-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All trees are now TerrainObjects from the beginning.
- Loading branch information
Showing
7 changed files
with
85 additions
and
49 deletions.
There are no files selected for viewing
40 changes: 0 additions & 40 deletions
40
God Game/Assets/PlayModeTests/FreeFallingObjectPlayTests.cs
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
God Game/Assets/PlayModeTests/TerrainObjectScriptPlayTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using UnityEngine; | ||
using UnityEngine.TestTools; | ||
using NUnit.Framework; | ||
using System.Collections; | ||
|
||
public class TerrainObjectScriptPlayTests { | ||
[UnityTest] | ||
public IEnumerator objectShouldBeDestroyedWhenTooHigh() { | ||
var gameObject = new GameObject(); | ||
var fallingScripts = gameObject.AddComponent<TerrainObjectScript>(); | ||
|
||
yield return null; | ||
|
||
Assert.IsFalse(gameObject == null); | ||
|
||
fallingScripts.transform.position = new Vector3(0, Constants.MaxHeight + 1, 0); | ||
|
||
yield return null; | ||
yield return null; | ||
|
||
Assert.IsTrue(gameObject == null); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator objectShouldBeDestroyedWhenTooLow() { | ||
var gameObject = new GameObject(); | ||
var fallingScripts = gameObject.AddComponent<TerrainObjectScript>(); | ||
|
||
yield return null; | ||
|
||
Assert.IsFalse(gameObject == null); | ||
|
||
fallingScripts.transform.position = new Vector3(0, Constants.MaxHeight + 1, 0); | ||
|
||
yield return null; | ||
yield return null; | ||
|
||
Assert.IsTrue(gameObject == null); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator objectShouldDisconnectWhenRotationIsLarge() { | ||
var gameObject = new GameObject(); | ||
var parent = new GameObject(); | ||
var fallingScripts = gameObject.AddComponent<TerrainObjectScript>(); | ||
gameObject.transform.parent = parent.transform; | ||
|
||
yield return null; | ||
|
||
Assert.AreEqual(parent.transform, gameObject.transform.parent); | ||
Assert.IsNull(gameObject.GetComponent<Rigidbody>()); | ||
|
||
fallingScripts.transform.rotation = Quaternion.FromToRotation(Vector3.up, new Vector3(1, 1, 0)); | ||
|
||
yield return null; | ||
|
||
Assert.AreEqual(parent.transform, gameObject.transform.parent); | ||
Assert.IsNull(gameObject.GetComponent<Rigidbody>()); | ||
|
||
fallingScripts.transform.rotation = fallingScripts.transform.rotation = Quaternion.FromToRotation(Vector3.up, new Vector3(1, 1, 1)); | ||
|
||
yield return null; | ||
|
||
Assert.IsNull(gameObject.transform.parent); | ||
Assert.IsNotNull(gameObject.GetComponent<Rigidbody>()); | ||
|
||
yield return null; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 13 additions & 6 deletions
19
...e/Assets/Scripts/Map/FreeFallingObject.cs → ...Assets/Scripts/Map/TerrainObjectScript.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
using UnityEngine; | ||
|
||
public class FreeFallingObject : MonoBehaviour { | ||
// Update is called once per frame | ||
void Update () { | ||
public class TerrainObjectScript : MonoBehaviour { | ||
|
||
void Update () { | ||
if (transform.position.y > Constants.MaxHeight || transform.position.y < Constants.MinHeight) { | ||
Destroy(gameObject); | ||
return; | ||
} | ||
|
||
if (transform.parent == null) { | ||
return; | ||
} | ||
} | ||
|
||
if (Vector3.Angle(transform.up, Vector3.up) > 45) { | ||
TerrainObjectScript.freeObject(transform); | ||
} | ||
} | ||
|
||
public static void freeObject(Transform obj) { | ||
obj.parent = null; | ||
Rigidbody rigidBody = obj.gameObject.AddComponent<Rigidbody>(); | ||
rigidBody.mass = 5; | ||
rigidBody.useGravity = true; | ||
obj.GetComponent<Collider>().enabled = true; | ||
obj.gameObject.AddComponent<FreeFallingObject>(); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters