*
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
public delegate void ButtonDelegate(Button sender);
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class Button : MonoBehaviour {
|
||||
public Texture2D image;
|
||||
public Texture2D mask;
|
||||
public Vector2 size;
|
||||
public Material mat;
|
||||
public Color baseColor;
|
||||
private bool pressed;
|
||||
private Rect buttonRect;
|
||||
public event ButtonDelegate EventDown;
|
||||
public event ButtonDelegate EventUp;
|
||||
public event ButtonDelegate EventClick;
|
||||
private int fingerId = -1;
|
||||
|
||||
private void OnDown(){
|
||||
if (EventDown != null) {
|
||||
EventDown(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUp(){
|
||||
if (EventUp != null) {
|
||||
EventUp(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClick(){
|
||||
if (EventClick != null) {
|
||||
EventClick(this);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Pressed{
|
||||
get{return pressed; }
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
EventClick += new ButtonDelegate (clickDelegate);
|
||||
}
|
||||
|
||||
void clickDelegate(Button sender){
|
||||
}
|
||||
|
||||
bool PointInButton(Vector2 point){
|
||||
return buttonRect.Contains(point);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
buttonRect = new Rect (
|
||||
transform.position.x - size.x / 2,
|
||||
transform.position.y - size.y / 2,
|
||||
size.x, size.y);
|
||||
|
||||
if (pressed) {
|
||||
Vector2 releasePoint = Vector2.zero;
|
||||
if (IsReleased (ref releasePoint)) {
|
||||
if (PointInButton (releasePoint)) {
|
||||
OnUp ();
|
||||
OnClick ();
|
||||
}
|
||||
pressed = false;
|
||||
}
|
||||
} else {
|
||||
if(IsPressing()){
|
||||
pressed = true;
|
||||
OnDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IsReleased(ref Vector2 point){
|
||||
#if !UNITY_WP8 || UNITY_EDITOR
|
||||
|
||||
point = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
|
||||
return Input.GetKeyUp (KeyCode.Mouse0);
|
||||
#else
|
||||
foreach (var t in Input.touches) {
|
||||
if(t.fingerId == fingerId){
|
||||
if((t.phase == TouchPhase.Canceled) || (t.phase == TouchPhase.Ended)){
|
||||
point = new Vector2(t.position.x, Screen.height - t.position.y);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
point = new Vector2(-1, -1);
|
||||
return true;
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool IsPressing(){
|
||||
#if !UNITY_WP8 || UNITY_EDITOR
|
||||
if (Input.GetKeyDown (KeyCode.Mouse0)) {
|
||||
Vector2 position = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
|
||||
return buttonRect.Contains(position);
|
||||
}
|
||||
#else
|
||||
foreach(var t in Input.touches){
|
||||
Vector2 position = new Vector2(t.position.x, Screen.height - t.position.y);
|
||||
if(buttonRect.Contains(t.position)){
|
||||
fingerId = t.fingerId;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnGUI(){
|
||||
if (Event.current.type == EventType.Repaint) {
|
||||
mat.SetColor("_TintColor", baseColor);
|
||||
Graphics.DrawTexture (buttonRect, image, mat);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05efe282fce56ec479bf3e771c883302
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class CrossHair : MonoBehaviour {
|
||||
public Texture CrosshairTexture;
|
||||
private RaycastHit hit;
|
||||
private bool hasHit;
|
||||
private Vector3 target;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
public Vector3 Target{
|
||||
get{return target; }
|
||||
}
|
||||
|
||||
public bool HasHit{
|
||||
get{return hasHit; }
|
||||
}
|
||||
|
||||
public RaycastHit HitInfo{
|
||||
get{return hit; }
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
var ray = camera.ViewportPointToRay (new Vector3(0.5f,0.5f,0.0f));
|
||||
hasHit = Physics.Raycast (ray, out hit);
|
||||
if (hasHit) {
|
||||
target = hit.point;
|
||||
} else {
|
||||
target = ray.origin + ray.direction.normalized * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnGUI(){
|
||||
Vector2 screenCenter = new Vector2 (Screen.width / 2, Screen.height / 2);
|
||||
|
||||
Graphics.DrawTexture (new Rect(
|
||||
screenCenter.x - (CrosshairTexture.width / 2),
|
||||
screenCenter.y - (CrosshairTexture.height / 2),
|
||||
CrosshairTexture.width,
|
||||
CrosshairTexture.height), CrosshairTexture);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2b680561d556d844b7937bc2a20e2f6
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,71 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class Crossbow : Gun {
|
||||
public Button fireButton;
|
||||
public CrossHair crosshair;
|
||||
public GameObject arrowTemplate;
|
||||
private GameObject fireSpot;
|
||||
private SoundTable sounds;
|
||||
public AudioClip singleShotSound;
|
||||
public AudioClip reloadSound;
|
||||
private AudioSource shootAudioSource;
|
||||
private const int cartridgeSize = 30;
|
||||
private int loadedAmmo = 0;
|
||||
private int availableAmmo = cartridgeSize * 5;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
fireButton.EventDown += new ButtonDelegate (onFire);
|
||||
fireSpot = Utils.FindChildRecursive (gameObject, "FireSpot");
|
||||
shootAudioSource = fireSpot.AddComponent<AudioSource> ();
|
||||
sounds = gameObject.GetComponent<SoundTable> ();
|
||||
Reload ();
|
||||
}
|
||||
|
||||
void onFire(Button btn){
|
||||
if (loadedAmmo > 0) {
|
||||
var shootTarget = crosshair.Target;
|
||||
GameObject arrow = (GameObject)Instantiate (arrowTemplate);
|
||||
arrow.transform.position = transform.TransformPoint (Vector3.zero);
|
||||
CrossbowArrow scr = arrow.GetComponent<CrossbowArrow> ();
|
||||
scr.StartPoint = fireSpot.transform.TransformPoint (Vector3.zero);
|
||||
scr.EndPoint = shootTarget;
|
||||
scr.Speed = 40;
|
||||
arrow.SetActive (true);
|
||||
|
||||
//shootAudioSource.PlayOneShot (singleShotSound);
|
||||
loadedAmmo --;
|
||||
} else {
|
||||
shootAudioSource.PlayOneShot (reloadSound);
|
||||
Reload();
|
||||
}
|
||||
}
|
||||
|
||||
void Reload(){
|
||||
if (loadedAmmo < cartridgeSize && availableAmmo > 0) {
|
||||
int emptyCount = cartridgeSize - loadedAmmo;
|
||||
int loadCount = emptyCount > availableAmmo ? availableAmmo : emptyCount;
|
||||
loadedAmmo += loadCount;
|
||||
availableAmmo -= loadCount;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
public override int GetLoadedAmmo(){
|
||||
return loadedAmmo;
|
||||
}
|
||||
public override int GetAvailableAmmo(){
|
||||
return availableAmmo;
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Gizmos.DrawWireSphere (transform.position, 0.5f);
|
||||
Gizmos.DrawRay ( new Ray(transform.position, transform.forward * 2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 871a63b6e434db64c9d59993dcb34518
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class CrossbowArrow : MonoBehaviour {
|
||||
|
||||
public Vector3 StartPoint;
|
||||
public Vector3 EndPoint;
|
||||
public Vector3 CurrentPosition;
|
||||
public Vector3 NextPosition;
|
||||
public float Speed;
|
||||
public GameObject physicsHits;
|
||||
private float distance = 0.0f;
|
||||
private RaycastHit hit;
|
||||
private Vector3 forward;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
forward = (EndPoint - StartPoint).normalized;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
CurrentPosition = StartPoint + (EndPoint - StartPoint).normalized * distance;
|
||||
distance += Time.deltaTime * Speed;
|
||||
|
||||
NextPosition = StartPoint + (EndPoint - StartPoint).normalized * distance;
|
||||
|
||||
|
||||
if (distance >= 50) {
|
||||
Destroy (this);
|
||||
} else {
|
||||
RaycastHit hit;
|
||||
if(Physics.Raycast(new Ray(CurrentPosition, forward), out hit)){
|
||||
//Debug.Log("Pointing on: " + hit.collider.gameObject.name);
|
||||
if(hit.distance <= (NextPosition - CurrentPosition).magnitude){
|
||||
NextPosition = CurrentPosition + transform.forward * hit.distance;
|
||||
Destroy(gameObject);
|
||||
|
||||
var mat = hit.collider.sharedMaterial;
|
||||
string hitName = "HitDefault";
|
||||
if(mat != null && mat.name == "Glass"){
|
||||
hitName = "HitGlass";
|
||||
}
|
||||
|
||||
GameObject hitObjSrc = physicsHits.transform.FindChild(hitName).gameObject;
|
||||
GameObject hitObj = (GameObject)Instantiate(hitObjSrc);
|
||||
hitObj.transform.localPosition = hit.point;
|
||||
hitObj.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
|
||||
hitObj.SetActive(true);
|
||||
|
||||
//hit.normal
|
||||
|
||||
}
|
||||
}else{
|
||||
//Debug.Log("Pointing on: Nothing");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
transform.position = NextPosition;
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Gizmos.DrawLine (CurrentPosition, CurrentPosition + forward * 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93a3eab38422a8244bf1a1a95f4ca6f7
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public interface IDamageable{
|
||||
void OnDamage ();
|
||||
}
|
||||
|
||||
public class Enemy1 : MonoBehaviour, IDamageable {
|
||||
|
||||
public void OnDamage (){
|
||||
Debug.Log ("Damage");
|
||||
}
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efb51db4089bb2c4b93965b06f099f4c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Escape : MonoBehaviour {
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
if (Input.GetKeyDown (KeyCode.Escape)) {
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc81be5671185c64e82d5849d24ebcd5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Gun : MonoBehaviour {
|
||||
|
||||
public virtual void Start(){
|
||||
|
||||
}
|
||||
public virtual int GetAvailableAmmo(){
|
||||
return 0;
|
||||
}
|
||||
public virtual int GetLoadedAmmo(){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70ebe1a2fcf529142a25bf0765aceb4c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class ScreenSpacePosition{
|
||||
public bool Relative;
|
||||
public Vector2 Position;
|
||||
public Vector2 PixelPosition{
|
||||
get{
|
||||
if(Relative){
|
||||
return new Vector2(Position.x * Screen.width, Position.y * Screen.height);
|
||||
}else{
|
||||
return Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class GunStats : MonoBehaviour {
|
||||
public ScreenSpacePosition Position;
|
||||
private Gun _gun;
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
public void SetGun(Gun gun){
|
||||
_gun = gun;
|
||||
}
|
||||
|
||||
void OnGUI(){
|
||||
if (_gun != null) {
|
||||
GUI.Label (new Rect (Position.PixelPosition.x, Position.PixelPosition.y, 100, 100), string.Format("{0}/{1}", _gun.GetLoadedAmmo(), _gun.GetAvailableAmmo()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c524357d543e81349ac16d66f2f1c7da
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,183 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class Joystick : MonoBehaviour {
|
||||
public bool Relative = false;
|
||||
public float BaseJoystickRadius;
|
||||
public float StickRadius;
|
||||
public Texture2D circleImage;
|
||||
private Rect baseRect;
|
||||
private Rect stickRect;
|
||||
private Vector2 basePosition;
|
||||
private bool pressed = false;
|
||||
private Vector2 pressPosition;
|
||||
private Vector2 stickOffset;
|
||||
private Vector2 stickPosition;
|
||||
public Material Mat;
|
||||
public Color BaseColor;
|
||||
public Color StickColor;
|
||||
private int fingerId = -1;
|
||||
private float angle;
|
||||
public ScreenSpacePosition ScreenPosition;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
public float Angle{
|
||||
get{
|
||||
return angle;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Pressed{
|
||||
get{
|
||||
return pressed;
|
||||
}
|
||||
}
|
||||
|
||||
public float Value{
|
||||
get{
|
||||
return pressed ? Mathf.Clamp01(stickOffset.magnitude / BaseJoystickRadius) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public float ValueX{
|
||||
get{
|
||||
return pressed ? Mathf.Clamp((stickPosition.x - basePosition.x) / BaseJoystickRadius, -1, 1) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public float ValueY{
|
||||
get{
|
||||
return pressed ? Mathf.Clamp((stickPosition.y - basePosition.y) / BaseJoystickRadius, -1, 1) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 Direction{
|
||||
get{
|
||||
return pressed ? stickOffset.normalized : Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
bool InsideDefaultStick(Vector2 position){
|
||||
Vector2 diff = position - basePosition;
|
||||
return diff.magnitude <= StickRadius;
|
||||
}
|
||||
|
||||
bool GetPressPosition(ref Vector2 position){
|
||||
#if !UNITY_WP8 || UNITY_EDITOR
|
||||
if (Input.GetKeyDown (KeyCode.Mouse0)) {
|
||||
position = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
|
||||
return InsideDefaultStick(position);
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
for (var i = 0; i < Input.touchCount; ++i) {
|
||||
var tap = Input.GetTouch(i);
|
||||
if(tap.phase == TouchPhase.Began){
|
||||
position = new Vector2(tap.position.x, Screen.height - tap.position.y);
|
||||
if(InsideDefaultStick(position)){
|
||||
fingerId = tap.fingerId;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FindTouch(int finger, ref Touch t){
|
||||
foreach (var touch in Input.touches) {
|
||||
if(touch.fingerId == finger){
|
||||
t = touch;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Released(){
|
||||
#if !UNITY_WP8 || UNITY_EDITOR
|
||||
return Input.GetKeyUp (KeyCode.Mouse0);
|
||||
#else
|
||||
Touch t = new Touch();
|
||||
if(!FindTouch(fingerId, ref t)){
|
||||
return true;
|
||||
}
|
||||
return (t.phase == TouchPhase.Ended) || (t.phase == TouchPhase.Canceled);
|
||||
#endif
|
||||
}
|
||||
|
||||
Vector2 GetMovePosition(){
|
||||
#if !UNITY_WP8 || UNITY_EDITOR
|
||||
return new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
|
||||
#else
|
||||
Touch t = new Touch();
|
||||
FindTouch(fingerId, ref t);
|
||||
return new Vector2(t.position.x, Screen.height - t.position.y);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
basePosition = ScreenPosition.PixelPosition;
|
||||
stickPosition = basePosition;
|
||||
baseRect = new Rect (
|
||||
basePosition.x - BaseJoystickRadius,
|
||||
basePosition.y - BaseJoystickRadius,
|
||||
BaseJoystickRadius * 2.0f,
|
||||
BaseJoystickRadius * 2.0f);
|
||||
|
||||
if (!pressed) {
|
||||
if (GetPressPosition(ref pressPosition)) {
|
||||
pressed = true;
|
||||
}
|
||||
} else {
|
||||
if (Released()) {
|
||||
pressed = false;
|
||||
stickOffset = Vector2.zero;
|
||||
angle = 0;
|
||||
}else{
|
||||
Vector2 touchPosition = GetMovePosition();
|
||||
stickOffset = touchPosition - pressPosition;
|
||||
if (stickOffset.magnitude > BaseJoystickRadius) {
|
||||
stickPosition = basePosition + stickOffset.normalized * BaseJoystickRadius;
|
||||
} else {
|
||||
stickPosition = basePosition + stickOffset;
|
||||
}
|
||||
|
||||
Vector2 joyDir = Direction;
|
||||
angle = Mathf.Atan2(joyDir.x, joyDir.y);
|
||||
angle = (Mathf.PI - Mathf.Abs(angle)) * Mathf.Sign(angle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
stickRect = new Rect (
|
||||
stickPosition.x - StickRadius,
|
||||
stickPosition.y - StickRadius,
|
||||
StickRadius * 2.0f,
|
||||
StickRadius * 2.0f);
|
||||
|
||||
}
|
||||
|
||||
void OnGUI(){
|
||||
|
||||
//GUI.DrawTexture (stickRect, circleImage);
|
||||
if (Event.current.type == EventType.Repaint) {
|
||||
Mat.SetColor("_TintColor", BaseColor);
|
||||
Graphics.DrawTexture (baseRect, circleImage, Mat);
|
||||
Mat.SetColor("_TintColor", StickColor);
|
||||
Graphics.DrawTexture (stickRect, circleImage, Mat);
|
||||
}
|
||||
|
||||
GUI.Label(new Rect (
|
||||
baseRect.x,
|
||||
baseRect.y - 40,
|
||||
baseRect.width ,
|
||||
20), (ValueY).ToString("##.###"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb6745f19c7a74349a1ae40109de72a6
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public enum MaterialType{
|
||||
Default,
|
||||
Metal,
|
||||
Glass
|
||||
}
|
||||
|
||||
public class MaterialSounds : MonoBehaviour {
|
||||
public MaterialType materialType;
|
||||
public AudioClip[] Sounds;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3575c3a822c87d740a0eece75080ce94
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class PlayerController : MonoBehaviour {
|
||||
|
||||
public Joystick JoyMove;
|
||||
public Joystick JoyRotate;
|
||||
|
||||
public float moveSpeed = 1;
|
||||
private float rotateLeftRight = 0;
|
||||
private float rotateUpDown = 0;
|
||||
private float rotateSpeed = 50.0f;
|
||||
private GameObject cameraObject;
|
||||
public Button jumpButton;
|
||||
private CharacterController c;
|
||||
public CrossHair crosshair;
|
||||
private GameObject weaponSpot;
|
||||
private Gun[] guns;
|
||||
private Gun activeGun;
|
||||
private GunStats stats;
|
||||
private Vector3 speedVector = Vector3.zero;
|
||||
public float jumpForce = 8.0f;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
cameraObject = gameObject.transform.FindChild ("Camera").gameObject;
|
||||
rotateUpDown = transform.localEulerAngles.x;
|
||||
rotateLeftRight = transform.localEulerAngles.y;
|
||||
c = gameObject.GetComponent<CharacterController> ();
|
||||
stats = gameObject.GetComponent<GunStats> ();
|
||||
weaponSpot = Utils.FindChildRecursive (gameObject, "WeaponSpot");
|
||||
guns = weaponSpot.GetComponentsInChildren<Gun> (true);
|
||||
foreach (var gun in guns) {
|
||||
gun.gameObject.SetActive(false);
|
||||
}
|
||||
SwitchGun (0);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
if (c.isGrounded) {
|
||||
float angle = Mathf.Rad2Deg * JoyMove.Angle;
|
||||
var forward = transform.forward;
|
||||
Quaternion rotation = Quaternion.AngleAxis (angle, Vector3.up);
|
||||
speedVector = (rotation * forward);
|
||||
speedVector.y = 0;
|
||||
speedVector = speedVector.normalized * (JoyMove.Value * moveSpeed);
|
||||
|
||||
if(jumpButton.Pressed){
|
||||
speedVector.y = jumpForce;
|
||||
}
|
||||
}
|
||||
|
||||
speedVector.y -= 9.8f * (Time.deltaTime);
|
||||
c.Move (speedVector * Time.deltaTime);
|
||||
|
||||
if (JoyRotate != null && JoyRotate.Value != 0.0f) {
|
||||
rotateLeftRight += JoyRotate.ValueX * (rotateSpeed * Time.deltaTime);
|
||||
rotateUpDown += JoyRotate.ValueY * (rotateSpeed * Time.deltaTime);
|
||||
rotateUpDown = Mathf.Clamp(rotateUpDown, -90.0f, 90.0f);
|
||||
|
||||
cameraObject.transform.localEulerAngles = new Vector3(rotateUpDown,0, 0);
|
||||
transform.localEulerAngles = new Vector3(0,rotateLeftRight, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SwitchGun(int id){
|
||||
if (activeGun == guns[id]) {
|
||||
return;
|
||||
}
|
||||
if (activeGun != null) {
|
||||
activeGun.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
activeGun = guns[id];
|
||||
activeGun.gameObject.SetActive(true);
|
||||
stats.SetGun (activeGun);
|
||||
//Destroy (weaponSpot.transform.GetChild (0));
|
||||
//guns
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
if (c == null) {
|
||||
c = gameObject.GetComponent<CharacterController> ();
|
||||
}
|
||||
if(c != null){
|
||||
Gizmos.DrawWireCube (c.center + transform.position, new Vector3 (c.radius * 2, c.height, c.radius * 2));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd09b0d7006fe0941aaa3454bd9140de
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class SelfDestroy : MonoBehaviour {
|
||||
private float startTime;
|
||||
public float Delay = 1;
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
startTime = Time.time;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
if (Time.time >= startTime + Delay) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72c54ff680e4ab742b94b1f8e2cadc8f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class SoundPlayer : MonoBehaviour {
|
||||
public AudioClip[] sounds;
|
||||
private AudioSource audioSource;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
audioSource = gameObject.GetComponent<AudioSource>();
|
||||
if (sounds != null && audioSource != null) {
|
||||
AudioClip sound = sounds[Random.Range(0, sounds.Length - 1)];
|
||||
audioSource.PlayOneShot(sound);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d86233ecd0866b4986e3c42e0760cfb
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class SoundTable : MonoBehaviour {
|
||||
public MaterialSounds[] materialSounds;
|
||||
|
||||
public MaterialSounds FindSounds(MaterialType mat){
|
||||
if (materialSounds == null || materialSounds.Length < 1) {
|
||||
return null;
|
||||
}
|
||||
foreach (var list in materialSounds) {
|
||||
if(list.materialType == mat){
|
||||
return list;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22d33d3c09e907c4bac34997b4578556
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Utils {
|
||||
public static GameObject FindChildRecursive(GameObject obj, string name){
|
||||
var child = obj.transform.FindChild (name);
|
||||
if (child != null) {
|
||||
return child.gameObject;
|
||||
}
|
||||
|
||||
for(int i = 0; i < obj.transform.childCount; ++i){
|
||||
var rchild = FindChildRecursive(obj.transform.GetChild(i).gameObject, name);
|
||||
if(rchild != null){
|
||||
return rchild.gameObject;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c91b3b095f319bd4fb01145cbdab66fd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
Reference in New Issue
Block a user