-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class BulletBehavior : MonoBehaviour | ||
{ | ||
#region Properties | ||
public float m_Speed = 3.0f; | ||
Rigidbody2D m_RigidB2D; | ||
#endregion | ||
|
||
|
||
#region Main methods | ||
void Start () | ||
{ | ||
m_RigidB2D = GetComponent<Rigidbody2D>(); | ||
m_RigidB2D.velocity = Vector2.right * m_Speed; | ||
} | ||
|
||
void FixedUpdate() | ||
{ | ||
// Bullet destruction default period (if never colliding) | ||
Destroy(gameObject, 1); | ||
} | ||
#endregion | ||
|
||
|
||
#region Utils | ||
|
||
// TODO : destroy bullet after few seconds (in case of never collision entering) | ||
|
||
|
||
void OnTriggerEnter2D(Collider2D other) | ||
{ | ||
// If collision on a target, destroy it too | ||
if (other.gameObject.CompareTag("Target")) | ||
{ | ||
Destroy(gameObject); | ||
Destroy(other.gameObject); | ||
} | ||
} | ||
|
||
void OnCollisionEnter2D(Collision2D other) | ||
{ | ||
// Destroy the bullet if entering with "Ground"-tagged gameObject | ||
if (other.gameObject.CompareTag("Ground")) | ||
{ | ||
Destroy(gameObject); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class PlayerBehavior : MonoBehaviour | ||
{ | ||
|
||
#region Public properties | ||
public string m_Axis; | ||
public float m_MoveSpeed = 10.0f; | ||
public float m_JumpSpeed = 10.0f; | ||
#endregion | ||
|
||
|
||
#region Main methods | ||
void Start () | ||
{ | ||
m_RigidB2D = GetComponent<Rigidbody2D>(); | ||
} | ||
|
||
void Update() | ||
{ | ||
|
||
} | ||
|
||
void FixedUpdate () | ||
{ | ||
m_CurrentPosition = transform.position; | ||
|
||
InstantiateBullet(); | ||
Move(); | ||
Jump(); | ||
} | ||
#endregion | ||
|
||
|
||
#region Utils | ||
// TODO : input DIRECTION ! (= player direction; left or right) | ||
void InstantiateBullet() | ||
{ | ||
if (Input.GetKeyDown(KeyCode.Return)) | ||
{ | ||
GameObject BulletPrefab = (GameObject)Instantiate(Resources.Load("prefabs/PrefabBullet")); | ||
BulletPrefab.transform.position = m_CurrentPosition; | ||
} | ||
} | ||
|
||
void Move() | ||
{ | ||
float Axis = Input.GetAxisRaw(m_Axis); | ||
m_RigidB2D.velocity = new Vector2(Axis, 0) * m_MoveSpeed; | ||
} | ||
|
||
void Jump() | ||
{ | ||
if (Input.GetKeyDown(KeyCode.Space) && m_RigidB2D.velocity.y == 0) | ||
{ | ||
m_RigidB2D.velocity = (Vector2.up * m_JumpSpeed); | ||
} | ||
} | ||
|
||
void OnGUI() | ||
{ | ||
GUILayout.Button("x: " + m_RigidB2D.velocity.x + " \n y:" + m_RigidB2D.velocity.y); | ||
} | ||
#endregion | ||
|
||
|
||
|
||
#region Private properties | ||
|
||
Vector3 m_CurrentPosition; | ||
Rigidbody2D m_RigidB2D; | ||
|
||
#endregion | ||
|
||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class WallBehaviour : MonoBehaviour { | ||
|
||
|
||
void Start () { | ||
|
||
} | ||
|
||
|
||
void Update () { | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.