コード例 #1
0
    /*
     * void CmdExit()
     * {
     *      RpcShutDown();
     * }
     *
     *
     *
     * void RpcShutDown()
     * {
     *      Application.Quit();
     * }
     */
//	public void idle_mode(){
//
//		Vector2 myVel = myBody.velocity;
//		myVel.x = Random.Range (-30.0f, 30.0f);
//		myVel.y = Random.Range (-10.0f, 18.0f);
//		myBody.velocity = myVel*0.1f;
//	}
//
//	[ServerCallback]
//	void OnTriggerEnter2D(Collider2D other) {
//		if (other.gameObject.CompareTag ("Submarine")) {
//			Debug.Log ("Submarine detected");
//			myBody.transform.position = Vector2.MoveTowards (myBody.transform.position, other.gameObject.transform.position, attack_speed);
//
//		} else if (other.gameObject.CompareTag ("Missile")) {
//			Debug.Log ("Dodging Missile");
//			myBody.transform.position = Vector2.MoveTowards (myBody.transform.position, -other.gameObject.transform.position, evade_speed);
//		}
//	}

//	void OnDestroy(){
//		Radar.RemoveRadarObject (this.gameObject);
//	}
//
    void OnCollisionEnter2D(Collision2D col)
    {
        GameObject hit = col.gameObject;

        //health.DecreaseHealth ();
        if (hit.GetComponent <SubmarineHealthSingle>() != null)
        {
            SubmarineHealthSingle health = hit.GetComponent <SubmarineHealthSingle>();
            if (health.currentHealth > 0f)
            {
                Debug.Log("EnemyController - Decreasing player health");
                health.DecreaseHealth();
                //health.currentHealth -= 10f;

                // Blobs should not die upon contact with player, can only be killed by missles...
                //EnemyBlobHealth enemyHealth = gameObject.GetComponent<EnemyBlobHealth> ();
                //enemyHealth.DecreaseHealth (hit.tag);
            }
        }

        /*
         * else if (health != null && health.currentHealth <= 0f) {
         *      Debug.Log ("Changing to End Panel");
         *
         *      Scene current = this.gameObject.scene;
         *      Debug.Log (current);
         *      GameObject[] scenes = current.GetRootGameObjects ();
         *      foreach (GameObject root in scenes) {
         *              Debug.Log (root);
         *              if (root.GetComponent<RectTransform> () != null) {
         *
         *                      Debug.Log ("found End");
         *                      GameObject endScene = GameObject.FindGameObjectWithTag ("End");
         *                      for (int i = 0; i < endScene.transform.childCount; i++) {
         *                              endScene.transform.GetChild (i).gameObject.SetActive (true);
         *                      }
         *                      //Debug.Log(endScene);
         *                      Debug.Log ("Finish enabling");
         *              } else if (root.GetComponent<NetworkManager> () != null) {
         *                      root.GetComponent<NetworkManager> ().StopHost ();
         *
         *              }
         *              //NetworkServer.Reset();
         *      }
         *      //NetworkServer.Stop
         *      //NetworkServer.Shutdown();
         *      //NetworkServer.DisconnectAll();
         *      NetworkServer.Reset ();
         *      //NetworkHost host = gameObject.GetComponent<NetworkHost>();
         *      //NetworkManager man = host.GetComponent<Network
         *      //man.StopHost();
         *      //CmdExit();
         *
         * }
         */
        else
        {
        }
    }
コード例 #2
0
    void OnTriggerEnter2D(Collider2D col)
    {
        GameObject hit = col.gameObject;

        if (hit.GetComponent <SubmarineHealthSingle>() != null)
        {
            SubmarineHealthSingle health = hit.GetComponent <SubmarineHealthSingle>();
            if (health.currentHealth < 100f)
            {
                health.currentHealth = 100f;
                health.SetHealthBar(health.currentHealth);
            }
            Destroy(this.gameObject);
        }
    }