Commit 74220f77 authored by kgingras's avatar kgingras
Browse files

Local game with respawning and scoring goals

parent 3b2d24be
using UnityEngine;
using System.Collections;
public class DestroyPS : MonoBehaviour {
// Use this for initialization
void Start () {
Invoke("Destroy", 1f);
}
void Destroy(){
Destroy(this.gameObject);
}
}
fileFormatVersion: 2
guid: b9c8548bbe73ab14eb7acc28e962f56d
timeCreated: 1455656684
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
public float ejectSpeed = 2000f;
public GameObject Team1Prefab;
public GameObject Team2Prefab;
public GameObject ballPrefab;
public Canvas _mainOverlay;
public Transform[] respawns1;
public Transform[] respawns2;
public GameObject spawner;
public GameObject _ball;
public int team1Score = 0;
public int team2Score = 0;
// Use this for initialization
void Start () {
Respawn("Team1");
Respawn("Team2");
Camera.main.gameObject.SetActive(false);
_mainOverlay.gameObject.SetActive(true);
SpawnBall();
}
// Update is called once per frame
void Update () {
}
public void Respawn(string team){
if(team == "Team1"){
Transform respawn = respawns1[Random.Range(0, respawns1.Length)].transform;
Instantiate(Team1Prefab, respawn.position, respawn.rotation);
}else{
Transform respawn = respawns2[Random.Range(0, respawns1.Length)].transform;
Instantiate(Team2Prefab, respawn.position, respawn.rotation);
}
}
public void SpawnBall(){
spawner.GetComponent<MeshRenderer>().enabled = true;
Invoke("MakeBall", 2f);
}
public void Score(string team){
if(team == "Team1"){
team2Score++;
}else{
team1Score++;
}
}
void MakeBall(){
_ball = (GameObject)Instantiate(ballPrefab, spawner.transform.position, Quaternion.identity);
Vector3 direction = new Vector3(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), 0f);
direction.Normalize();
_ball.GetComponent<Rigidbody>().AddForce(direction * ejectSpeed);
spawner.GetComponent<ParticleSystem>().Play();
spawner.GetComponent<MeshRenderer>().enabled = false;
}
}
fileFormatVersion: 2
guid: 98a3561530297404ca369bdce6601e6e
timeCreated: 1455650199
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public class GoalScript : MonoBehaviour {
public GameObject goalPS;
GameManager GMscript;
// Use this for initialization
void Start () {
GMscript = GameObject.Find("GameManager").GetComponent<GameManager>();
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision coll){
Debug.Log(coll.gameObject.layer );
Debug.Log(coll.gameObject.tag );
if(coll.gameObject.layer == LayerMask.NameToLayer("Goal")){
GMscript.Score(coll.gameObject.tag);
GMscript.SpawnBall();
Instantiate(goalPS, transform.position, Quaternion.identity);
Destroy(this.gameObject);
}
}
}
fileFormatVersion: 2
guid: 68a2b99cb57942c4eb605454fb8428e3
timeCreated: 1455654922
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public class LocalHP : MonoBehaviour {
public float _HP = 100;
public float takeDamage = 0f;
public float regenSpeed = 2f;
public float deadForce = 20f;
public Material deadMat;
public Camera _cam;
bool dead = false;
GameObject deadBody;
Vector3 deadVector = Vector3.zero;
// Use this for initialization
LocalCC CCscript;
void Start () {
CCscript = GetComponent<LocalCC>();
}
// Update is called once per frame
void Update () {
if(_HP <= 0 && !dead){
dead = true;
Dead ();
}
takeDamage -= Time.deltaTime;
if(takeDamage <0){
//regen HP
_HP = Mathf.Lerp (_HP, 100f, regenSpeed*Time.deltaTime);
}
}
void OnCollisionEnter(Collision coll){
if(coll.gameObject.name == "Bullet(Clone)" && coll.gameObject.tag != gameObject.tag){
takeDamage = 3f;
_HP -=20;
if(_HP <=0){
deadVector = coll.gameObject.GetComponent<Rigidbody>().velocity;
deadVector.Normalize();
}
Destroy(coll.gameObject);
}
}
void Dead(){
CCscript.dead = true;
deadBody = transform.FindChild("MotusMan_v2").gameObject;
deadBody.transform.FindChild("Motus_Man_01").gameObject.GetComponent<SkinnedMeshRenderer>().material = deadMat;
gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
gameObject.GetComponent<Rigidbody>().AddForce(deadVector*deadForce);
}
}
fileFormatVersion: 2
guid: 4a0579124ec5ec342b313d78e1ac6205
timeCreated: 1455646580
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 03eb77c556cce484ebd76cdaa4deeb97
folderAsset: yes
timeCreated: 1454465229
guid: f67d46c21cbb635478c04876ccb00a03
timeCreated: 1455596357
licenseType: Free
DefaultImporter:
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4b3818b4bb4ea2d4a8dbb7c6c290dfad
folderAsset: yes
timeCreated: 1454465229
guid: c72398231f6c3cb4899c95ac119f9acf
timeCreated: 1455594466
licenseType: Free
DefaultImporter:
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 9764338fccaaffc47bb233946af14b7f
folderAsset: yes
timeCreated: 1454465230
guid: d47170639ee1a3a4caf3125c1583f827
timeCreated: 1455596254
licenseType: Free
DefaultImporter:
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 9df7ea224866f8d42af18ba2733caea8
timeCreated: 1455596265
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d4862e80a43649c46bd06b7d2e2cb3b4
timeCreated: 1455594382
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment