Skip to content

Commit

Permalink
Assets updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-mohammadi committed Oct 19, 2018
1 parent d5fbf2d commit 9f6b4ba
Show file tree
Hide file tree
Showing 25 changed files with 174 additions and 7 deletions.
9 changes: 9 additions & 0 deletions Assets/Animation.meta

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

Binary file added Assets/Animation/Knife.controller
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Animation/Knife.controller.meta

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

Binary file added Assets/Animation/KnifeAnim.anim
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Animation/KnifeAnim.anim.meta

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

Binary file added Assets/Animation/Trunk.controller
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Animation/Trunk.controller.meta

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

Binary file added Assets/Animation/TrunkHitted.anim
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Animation/TrunkHitted.anim.meta

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

Binary file added Assets/Animation/TrunkNormal.anim
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Animation/TrunkNormal.anim.meta

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

Binary file modified Assets/Prefabs/Knife.prefab
Binary file not shown.
Binary file modified Assets/Scenes/Level1.unity
Binary file not shown.
Binary file added Assets/Scenes/Level2.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Scenes/Level2.unity.meta

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

14 changes: 13 additions & 1 deletion Assets/Scripts/Knife.cs
Expand Up @@ -7,20 +7,28 @@ public class Knife : MonoBehaviour {
public float speed = 20f;
public AudioClip hitSound;
Rigidbody2D knifeRigid;
bool moving = true;
bool moving = false;

GameObject spawn;

// Use this for initialization
void Start ()
{
// Identify Rigidbody
knifeRigid = GetComponent<Rigidbody2D>();

spawn = GameObject.Find("Spawn");
}

// Update is called once per frame
void FixedUpdate ()
{
if(moving)
knifeRigid.MovePosition(knifeRigid.position + Vector2.up * speed * Time.deltaTime);

// Knife start moving after click
if (Input.GetMouseButtonDown(0))
moving = true;
}

void OnTriggerEnter2D(Collider2D collider)
Expand All @@ -29,5 +37,9 @@ void OnTriggerEnter2D(Collider2D collider)
moving = false;
transform.parent = collider.transform;
GetComponent<AudioSource>().PlayOneShot(hitSound);
spawn.GetComponent<SpawnController>().CreateKnife();
collider.GetComponent<Animator>().SetTrigger("Hit");
collider.GetComponent<TrunkHealth>().Damage(1);
GetComponent<Knife>().enabled = false;
}
}
16 changes: 11 additions & 5 deletions Assets/Scripts/SpawnController.cs
Expand Up @@ -7,15 +7,21 @@ public class SpawnController : MonoBehaviour {
public GameObject knife;

// Use this for initialization
void Start () {

void Start ()
{
CreateKnife();
}

// Update is called once per frame
void Update ()
{
// If left click or touch, create new knife game object
if (Input.GetMouseButtonDown(0))
Instantiate(knife, transform.position, Quaternion.identity);

}

public void CreateKnife()
{
// Create knife if Trunk is alive!
if(GameObject.Find("Trunk").GetComponent<TrunkHealth>().health > 1)
Instantiate(knife, transform.position, Quaternion.identity);
}
}
65 changes: 65 additions & 0 deletions Assets/Scripts/TrunkHealth.cs
@@ -0,0 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class TrunkHealth : MonoBehaviour {

public int health = 5;

void Update()
{

}

// Decrease health
public void Damage(int value)
{
health -= value;

if (health == 0) // If there is no health
{
// Deactive Trunk collider
GetComponent<CircleCollider2D>().enabled = false;

// Trunk fragmentation
// Fragmention 1
transform.GetChild(0).GetComponent<Rigidbody>().isKinematic = false;
transform.GetChild(0).GetComponent<Rigidbody>().AddForce(400, 800, 0);
transform.GetChild(0).GetComponent<Rigidbody>().AddTorque(100, 100, 100);
transform.GetChild(0).parent = null;
// Fragmention 2
transform.GetChild(0).GetComponent<Rigidbody>().isKinematic = false;
transform.GetChild(0).GetComponent<Rigidbody>().AddForce(-400, 800, 0);
transform.GetChild(0).GetComponent<Rigidbody>().AddTorque(-100, 100, 100);
transform.GetChild(0).parent = null;
// Fragmention 3
transform.GetChild(0).GetComponent<Rigidbody>().isKinematic = false;
transform.GetChild(0).GetComponent<Rigidbody>().AddForce(0, 800, 0);
transform.GetChild(0).GetComponent<Rigidbody>().AddTorque(-200, 100, -100);
transform.GetChild(0).parent = null;

while (transform.childCount > 0)
{
// Knives apart from Trunk
transform.GetChild(0).GetComponent<Rigidbody2D>().isKinematic = false;
transform.GetChild(0).GetComponent<Rigidbody2D>().AddForce(new Vector2(Random.Range(-400f, 400f), Random.Range(400f, 800f)));
transform.GetChild(0).GetComponent<Rigidbody2D>().AddTorque(Random.Range(-400, 400));
transform.GetChild(0).parent = null;
}

// Show "YOU WIN!" and go to next level
GameObject.Find("TextMessage").GetComponent<Text>().text = "YOU WIN!";
StartCoroutine(NextLevel());
}
}

IEnumerator NextLevel()
{
// Go to next level after 2 seconds
yield return new WaitForSeconds(2f);
SceneManager.LoadScene("Level2");
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/TrunkHealth.cs.meta

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

4 changes: 3 additions & 1 deletion Assets/Scripts/TrunkRotate.cs
Expand Up @@ -4,6 +4,8 @@

public class TrunkRotate : MonoBehaviour {

public float speed = -1.5f;

// Use this for initialization
void Start () {

Expand All @@ -13,6 +15,6 @@ public class TrunkRotate : MonoBehaviour {
void Update ()
{
// Rotate Trunk in Z axis
transform.Rotate(new Vector3(0, 0, -1.5f));
transform.Rotate(new Vector3(0, 0, speed));
}
}
5 changes: 5 additions & 0 deletions Assets/TODO.txt
@@ -0,0 +1,5 @@
TODO...

1- Add Trunk fragmentation sound
2- Add next level sound
3- Add game over
8 changes: 8 additions & 0 deletions Assets/TODO.txt.meta

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

Binary file modified ProjectSettings/DynamicsManager.asset
Binary file not shown.
Binary file modified ProjectSettings/EditorBuildSettings.asset
Binary file not shown.
Binary file modified ProjectSettings/Physics2DSettings.asset
Binary file not shown.

0 comments on commit 9f6b4ba

Please sign in to comment.