zhaowei 8 роки тому
батько
коміт
24d14b726d

+ 9 - 0
Assets/Animation.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 74b0d9408a2289442b8c6a630d449b4d
+folderAsset: yes
+timeCreated: 1487229132
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Animation/Arrogance.anim


+ 8 - 0
Assets/Animation/Arrogance.anim.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 51a2de8f21fd09d42921d72de83991c9
+timeCreated: 1487228837
+licenseType: Free
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Animation/Arrogance.controller


+ 8 - 0
Assets/Animation/Arrogance.controller.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: cf3099ec7ed99274080bb0175e53be24
+timeCreated: 1487228837
+licenseType: Free
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Animation/explose.anim


+ 8 - 0
Assets/Animation/explose.anim.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 3393e8de4d3cf484fbd1a5b25575ea01
+timeCreated: 1487233696
+licenseType: Free
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Animation/explose.controller


+ 8 - 0
Assets/Animation/explose.controller.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: d6452fcb8b142664fb9241b72eb5b059
+timeCreated: 1487233696
+licenseType: Free
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Prefabs/enemy04.prefab


+ 8 - 0
Assets/Prefabs/enemy04.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: c842ccaccc12c33449e59974cdc75ab0
+timeCreated: 1487230785
+licenseType: Free
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Prefabs/enemy05.prefab


+ 8 - 0
Assets/Prefabs/enemy05.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 602e3d0ca3c931046936cfdfe9d81a72
+timeCreated: 1487230788
+licenseType: Free
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Prefabs/enemy06.prefab


+ 8 - 0
Assets/Prefabs/enemy06.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 70d4608e1faab444ab1de27fab9d86dd
+timeCreated: 1487230790
+licenseType: Free
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Prefabs/enemy07.prefab


+ 8 - 0
Assets/Prefabs/enemy07.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 4ff4f110e5193894492dc2d3c44bbb76
+timeCreated: 1487230792
+licenseType: Free
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Prefabs/explose.prefab


+ 8 - 0
Assets/Prefabs/explose.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 14c59d5941d4cb044a0f734838588597
+timeCreated: 1487233748
+licenseType: Free
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Scenes/main.unity


+ 14 - 11
Assets/Script/ArrowLook.cs

@@ -2,20 +2,23 @@
 using System.Collections.Generic;
 using UnityEngine;
 
-public class ArrowLook : MonoBehaviour {
+public class ArrowLook : MonoBehaviour
+{
+    public GameObject player;
+
+    // Use this for initialization
+    void Start()
+    {
 
-	// Use this for initialization
-	void Start () {
-		
-	}
-	
-	// Update is called once per frame
-	void Update () {
-      
     }
 
-    public void Look(GameObject cube)
+    // Update is called once per frame
+    void Update()
     {
-        transform.LookAt(cube.transform);
+        
     }
+
+    
+
+   
 }

+ 33 - 2
Assets/Script/CameraFollow.cs

@@ -10,6 +10,12 @@ public class CameraFollow : MonoBehaviour
 
     private Vector3 offsetPos;
 
+    private Vector3 originPos;
+    private Quaternion originRot;
+
+    public float shake_decay;
+    public float shake_intensity;
+
     // Use this for initialization
     void Start()
     {
@@ -19,7 +25,32 @@ public class CameraFollow : MonoBehaviour
     // Update is called once per frame
     void Update()
     {
-        Vector3 camNewPos = playerPos.position + offsetPos;
-        transform.position = Vector3.Lerp(transform.position, camNewPos, Time.deltaTime * smooth);
+        if (playerPos != null)
+        {
+            Vector3 camNewPos = playerPos.position + offsetPos;
+            transform.position = Vector3.Lerp(transform.position, camNewPos, Time.deltaTime * smooth);
+        }
+
+        if (shake_intensity > 0)
+        {
+            transform.position = originPos + Random.insideUnitSphere * shake_intensity;
+            transform.rotation = new Quaternion(
+            originRot.x + Random.Range(-shake_intensity, shake_intensity) * 0.2f,
+            originRot.y + Random.Range(-shake_intensity, shake_intensity) * 0.2f,
+            originRot.z + Random.Range(-shake_intensity, shake_intensity) * 0.2f,
+            originRot.w + Random.Range(-shake_intensity, shake_intensity) * 0.2f);
+            shake_intensity -= shake_decay;
+        }
+
+
+    }
+
+    public void Shake()
+    {
+        originPos = transform.position;
+        originRot = transform.rotation;
+        shake_intensity = 0.08f;
+        shake_decay = 0.002f;
+
     }
 }

+ 49 - 0
Assets/Script/EnemyControl.cs

@@ -0,0 +1,49 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class EnemyControl : MonoBehaviour
+{
+
+    public Vector2 startWait;
+    public Vector2 maneuverTime;
+    public Vector2 maneuverWait;
+    public float dodge;
+   
+    public float speed;
+
+    private float targetmaneuver;
+    
+
+    // Use this for initialization
+    void Start()
+    {
+        StartCoroutine(RandomDir());
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+
+    }
+
+    void FixedUpdate()
+    {
+        float newMan = Mathf.MoveTowardsAngle(transform.eulerAngles.z, targetmaneuver, Time.deltaTime * 10);
+
+        transform.rotation = Quaternion.Euler(0, 0, newMan);
+        transform.Translate(Vector3.up * Time.deltaTime * speed);
+    }
+
+    IEnumerator RandomDir()
+    {
+        yield return new WaitForSeconds(Random.Range(startWait.x, startWait.y));
+        while (true)
+        {
+            targetmaneuver = Random.Range(1, dodge) * -Mathf.Sign(transform.eulerAngles.z);
+            yield return new WaitForSeconds(Random.Range(maneuverTime.x, maneuverTime.y));
+            targetmaneuver = 0;
+            yield return new WaitForSeconds(Random.Range(maneuverWait.x, maneuverWait.y));
+        }
+    }
+}

+ 12 - 0
Assets/Script/EnemyControl.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 20036af795a42e34cbe1aa0f8b39bcc0
+timeCreated: 1487226252
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 59 - 0
Assets/Script/EnemyManage.cs

@@ -0,0 +1,59 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class EnemyManage : MonoBehaviour
+{
+    /// <summary>
+    /// 生成的物体
+    /// </summary>
+    public GameObject[] enemys;
+    /// <summary>
+    /// 生成的数量
+    /// </summary>
+    public int count;
+    /// <summary>
+    /// 开始等待的时间
+    /// </summary>
+    public float startWait;
+    /// <summary>
+    /// 结束等待的时间
+    /// </summary>
+    public float overWait;
+    /// <summary>
+    /// 生成等待时间
+    /// </summary>
+    public float buildWait;
+    /// <summary>
+    /// 生成的点
+    /// </summary>
+    public Transform[] points;
+
+    // Use this for initialization
+    void Start()
+    {
+        StartCoroutine(Create());
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+
+    }
+
+    IEnumerator Create()
+    {
+        yield return new WaitForSeconds(startWait);  //开始等待
+        while (true)
+        {
+            for (int i = 0; i < count; i++)
+            {
+                GameObject obj = enemys[Random.Range(0, enemys.Length)];  //随机生成一个敌人
+                Transform newPos = points[Random.Range(0, points.Length)];  //随机生成一个位置
+                Instantiate(obj, newPos.position, newPos.rotation);  //开始生成
+                yield return new WaitForSeconds(buildWait);    //生成等待
+            }
+            yield return new WaitForSeconds(overWait);   //等待下一次生成
+        }
+    }
+}

+ 12 - 0
Assets/Script/EnemyManage.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: aadcfe7377358784abf6a5ccdf50c7cb
+timeCreated: 1487230853
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 42 - 0
Assets/Script/GameManage.cs

@@ -0,0 +1,42 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.SceneManagement;
+
+public class GameManage : MonoBehaviour
+{
+    private static GameManage instance;
+    public static GameManage Instance
+    {
+        get
+        {
+            return instance;
+        }
+    }
+
+    public GameObject overPanel;
+    public GameObject player;
+
+    // Use this for initialization
+    void Start()
+    {
+        instance = this;
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+
+    }
+    
+    public void ResetGame()
+    {
+        SceneManager.LoadScene("main");
+    }
+
+    public void GameOver()
+    {
+        overPanel.SetActive(true);
+        Destroy(player);
+    }
+}

+ 12 - 0
Assets/Script/GameManage.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: e7bdd0e5b984390449b3ccb7b439d3d6
+timeCreated: 1487235785
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 57 - 2
Assets/Script/PlayerControl.cs

@@ -1,19 +1,48 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using UnityEngine.UI;
 
 public class PlayerControl : MonoBehaviour
 {
+    /// <summary>
+    /// 最小速度
+    /// </summary>
     public float minSpeed = 0.7f;
+    /// <summary>
+    /// 最大速度
+    /// </summary>
     public float maxSpeed = 1.4f;
+    /// <summary>
+    /// 爆炸特效
+    /// </summary>
+    public GameObject explose;
 
+    public float currentValue;
+    public float maxValue = 100;
+
+    public Slider armorSlider;
+    public Text currentText;
+    public Text maxText;
+
+    private CameraFollow cf;
+
+    /// <summary>
+    /// 鼠标到飞船的距离
+    /// </summary>
     private float dis = 0;
+    /// <summary>
+    /// 飞船的速度
+    /// </summary>
     private float player_speed = 0;
 
     // Use this for initialization
     void Start()
     {
-
+        currentValue = maxValue;
+        UpdateContent();
+        
+        cf = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraFollow>();
     }
 
     // Update is called once per frame
@@ -48,10 +77,36 @@ public class PlayerControl : MonoBehaviour
 
     void OnTriggerEnter2D(Collider2D other)
     {
-        Destroy(other.gameObject);
+        if (other.tag == "enemy")
+        {
+            
+            Instantiate(explose, other.gameObject.transform.position, Quaternion.identity);
+            cf.Shake();
+            GetHurt(50);
+            Destroy(other.gameObject);
+        }
     }
 
+    void GetHurt(int damage)
+    {
+        if (currentValue > 0)
+        {
+            currentValue -= damage;
+            UpdateContent();
+            if (currentValue <= 0)
+            {
+                Instantiate(explose, transform.position, Quaternion.identity);
+                GameManage.Instance.GameOver();
+            }
+        }
+    }
 
+    void UpdateContent()
+    {
+        currentText.text = currentValue.ToString();
+        maxText.text = "/" + maxValue.ToString();
+        armorSlider.value = (currentValue / maxValue);
+    }
 
 
 }