Skip to content

Commit

Permalink
FreeFallingObject: Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
nihohit committed Oct 8, 2017
1 parent faf807d commit 46ef59d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
40 changes: 40 additions & 0 deletions God Game/Assets/PlayModeTests/FreeFallingObjectPlayTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;

public class FreeFallingObjectPlayTests {
[UnityTest]
public IEnumerator objectShouldBeDestroyedWhenTooHigh() {
var gameObject = new GameObject();
var fallingScripts = gameObject.AddComponent<FreeFallingObject>();

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<FreeFallingObject>();

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);
}
}
12 changes: 12 additions & 0 deletions God Game/Assets/PlayModeTests/FreeFallingObjectPlayTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions God Game/Assets/Scripts/Map/FreeFallingObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using UnityEngine;

public class FreeFallingObject : MonoBehaviour {
// Update is called once per frame
void Update () {
if (transform.position.y > Constants.MaxHeight || transform.position.y < Constants.MinHeight) {
Destroy(gameObject);
}
}

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>();
}
}
12 changes: 12 additions & 0 deletions God Game/Assets/Scripts/Map/FreeFallingObject.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46ef59d

Please sign in to comment.