Bläddra i källkod

PowerDropes can be collected by players

DasGewehr 9 år sedan
förälder
incheckning
f3ffd68bd2

+ 2 - 0
game/Assets/Prefabs/Player.prefab

@@ -431,11 +431,13 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 7e52d9351376b9245b9e7a5696aa1fb6, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  powerLevel: 4
   startSpeed: 5
   lookSmoothingSeconds: 0.05
   cameraSmoothingSeconds: 1
   bulletUpBias: 0.1
   bulletForce: 20
+  powerLevelMax: 8
   gunTransform: {fileID: 4475041197474250}
   bulletPrefab: {fileID: 54626927522511238, guid: 3c7966951ee835c45be4199d01da6b8d,
     type: 2}

+ 2 - 2
game/Assets/Prefabs/PowerDrop.prefab

@@ -263,14 +263,14 @@ RectTransform:
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 100100000}
   m_GameObject: {fileID: 1517408471003036}
-  m_LocalRotation: {x: -0.7071068, y: 0, z: 0, w: 0.7071068}
+  m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
   m_LocalPosition: {x: 0, y: 0, z: 0}
   m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
   m_Children:
   - {fileID: 224092679048033082}
   m_Father: {fileID: 4776271435490680}
   m_RootOrder: 0
-  m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
+  m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
   m_AnchoredPosition: {x: 0, y: 0}

+ 20 - 1
game/Assets/Scripts/Player.cs

@@ -4,12 +4,31 @@ using UnityEngine;
 
 public class Player : MonoBehaviour
 {
+    [SerializeField]
+    private float powerLevel;
+    public float PowerLevel
+    {
+        get
+        {
+            return powerLevel;
+        }
+        set
+        {
+            powerLevel = value;
+
+            if (powerLevel > powerLevelMax)
+            {
+                powerLevel = powerLevelMax;
+            }
+        }
+    }
+
     public float startSpeed = 5f;
     public float lookSmoothingSeconds = 0.05f;
     public float cameraSmoothingSeconds = 1;
     public float bulletUpBias = 0.1f;
     public float bulletForce = 10f;
-    public float powerLevel;
+    public float powerLevelMax = 8.0f;
     public Transform gunTransform;
     public Rigidbody bulletPrefab;
     public Light muzzleLight;

+ 19 - 1
game/Assets/Scripts/PowerDrop.cs

@@ -7,8 +7,21 @@ public class PowerDrop : MonoBehaviour
     public float powerAmount = -100.0f;
 
     [SerializeField]
-    private UnityEngine.UI.Text textField; 
+    private UnityEngine.UI.Text textField;
+    private bool popped = false;
 
+    void OnTriggerEnter(Collider other)
+    {
+        if (!popped)
+        {
+            if (other.tag == "Player")
+            {
+                other.GetComponent<Player>().PowerLevel += powerAmount;
+                popped = true;
+                Pop();
+            }
+        }
+    }
 
 	// Use this for initialization
 	void Start () {
@@ -19,4 +32,9 @@ public class PowerDrop : MonoBehaviour
 	void Update () {
 		
 	}
+
+    private void Pop()
+    {
+        GameObject.Destroy(gameObject);
+    }
 }