Commit 3c8982aa by Tim Reiter

players are now loaded from xml (+ fixed a bug when the player picked up the portable fire)

parent 83bf8ea8
...@@ -4,8 +4,12 @@ ...@@ -4,8 +4,12 @@
<Developer StartLevel="0" /> <Developer StartLevel="0" />
<Level> <Level>
<Item prefab="Trap" x="-2.2" y="-0.1" rot="90" /> <Item prefab="Player Two" x="-3.05" y="2.06" />
<Item prefab="ground" x="9.3" y="-0.7" scalex="200" /> <Item prefab="Player One" x="-0.23" y="2.06" />
<Item prefab="Trap" x="-5.02" y="-0.57" rot="90" />
<Item prefab="ground" x="1.51" y="-0.8" scalex="58.39" />
<Item prefab="Turret" x="4.47" y="0.71" />
<Item prefab="PortableFire" x="4.04" y="-0.22" scalex="0.2" scaley="0.2" />
</Level> </Level>
<Level> <Level>
<Item prefab="PlayerStartPosition" x="5.11" y="-0.92" /> <Item prefab="PlayerStartPosition" x="5.11" y="-0.92" />
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: 8d9c84360d70c1b44af690dc244612a0 guid: 329ca4a74de8c8a438a191940544e5e1
timeCreated: 1433461451 timeCreated: 1433500438
licenseType: Free licenseType: Free
NativeFormatImporter: NativeFormatImporter:
userData: userData:
......
fileFormatVersion: 2
guid: 6c6daf85837b9f542bcb18f819b9d8a8
timeCreated: 1433500442
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2 fileFormatVersion: 2
guid: e0d90fce50c24884c8d83b9d365a5fe3 guid: 3ad7c167097946b408dbef72e2814b8f
timeCreated: 1433446163 timeCreated: 1433501024
licenseType: Free licenseType: Free
NativeFormatImporter: NativeFormatImporter:
userData: userData:
......
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<Levels xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Levels xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Level> <Level>
<Item prefab="Trap" x="-2.2" y="-0.1" rot="90" /> <Item prefab="Player Two" x="-3.05" y="2.06" />
<Item prefab="ground" x="9.3" y="-0.7" scalex="200" /> <Item prefab="Player One" x="-0.23" y="2.06" />
<Item prefab="Trap" x="-5.02" y="-0.57" rot="90" />
<Item prefab="ground" x="1.51" y="-0.8" scalex="58.39" />
<Item prefab="Turret" x="4.47" y="0.71" />
<Item prefab="PortableFire" x="4.04" y="-0.22" scalex="0.2" scaley="0.2" />
</Level> </Level>
</Levels> </Levels>
\ No newline at end of file
...@@ -7,18 +7,21 @@ public class FireScript : MonoBehaviour { ...@@ -7,18 +7,21 @@ public class FireScript : MonoBehaviour {
public float constantDamagepoints = 0.1f; public float constantDamagepoints = 0.1f;
public float burningTime = 10; public float burningTime = 10f;
// Use this for initialization private Vector3 startScale; //fixes a bug: scale of fire was 0 when attached to the player.
void Start () {
Invoke("stopBurning", burningTime);
void Start()
{
startScale = transform.localScale;
} }
// Update is called once per frame // Update is called once per frame
void Update () { void Update () {
if (parentHealth != null) if (parentHealth)
{ {
parentHealth.changeHealthBy(-constantDamagepoints); parentHealth.changeHealthBy(-constantDamagepoints * Time.deltaTime);
} }
} }
...@@ -29,6 +32,8 @@ public class FireScript : MonoBehaviour { ...@@ -29,6 +32,8 @@ public class FireScript : MonoBehaviour {
parentHealth = other.GetComponent<PlayerHealth>(); parentHealth = other.GetComponent<PlayerHealth>();
transform.position = other.transform.position; //hier schon position setzen transform.position = other.transform.position; //hier schon position setzen
transform.parent = other.transform; transform.parent = other.transform;
transform.localScale = startScale;
Invoke("stopBurning", burningTime);
} }
} }
......
using UnityEngine;
using System.Collections;
public class GameMaster : MonoBehaviour {
DeserializedLevelsLoader levelLoader;
// Use this for initialization
void Start () {
levelLoader = new DeserializedLevelsLoader();
levelLoader.loadLevel();
}
// Update is called once per frame
void Update () {
}
}
fileFormatVersion: 2 fileFormatVersion: 2
guid: 01cdeb3258bc3446ba8846c11515fc68 guid: 50166dd06214cc844822e30d279ffe94
timeCreated: 1433499967
licenseType: Free
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public class PlayScript : MonoBehaviour {
DeserializedLevelsLoader d;
void Start ()
{
d = new DeserializedLevelsLoader();
d.loadLevel();
}
}
...@@ -8,10 +8,18 @@ public class PlayerHealth : MonoBehaviour { ...@@ -8,10 +8,18 @@ public class PlayerHealth : MonoBehaviour {
public float currentHealth = 100; public float currentHealth = 100;
private bool alive = true; private bool alive = true;
public Scrollbar healthbar; private Scrollbar healthbar;
private PlayerControl playerControl;
private GameStateTracker gameStateTracker;
private bool hasShield = false; private bool hasShield = false;
void Start()
{
gameStateTracker = GameObject.Find("GameMaster").GetComponent<GameStateTracker>(); //warning: geht kaputt wenn der name "Game Master" sich aendert.
playerControl = gameObject.GetComponent<PlayerControl>();
string healthbarName = "HealthBar" + playerControl.playerNumber.ToString();
healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>();
}
// Update is called once per frame // Update is called once per frame
void Update () { void Update () {
...@@ -19,7 +27,7 @@ public class PlayerHealth : MonoBehaviour { ...@@ -19,7 +27,7 @@ public class PlayerHealth : MonoBehaviour {
{ {
Debug.Log("Player " + name + " dead."); Debug.Log("Player " + name + " dead.");
alive = false; alive = false;
GameObject.Find("GameStateTracker").GetComponent<GameStateTracker>().playerDied(name); gameStateTracker.playerDied(name);
Destroy(gameObject); Destroy(gameObject);
} }
} }
......
No preview for this file type
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