Exemple #1
0
    void OnEnemy(SocketIOEvent socketIOEvent)
    {
        print("An enemy");
        string data = socketIOEvent.data.ToString();

        print("your Enemy JSON data was recieved");
        EnemyJSON currentEnemyJSON = EnemyJSON.CreateFromJSON(data);

        print("your JSON was created : " + data);
        Vector3 position = new Vector3(currentEnemyJSON.enemyPosition[0], currentEnemyJSON.enemyPosition[1], currentEnemyJSON.enemyPosition[2]);

        print("your name isssssssssssssssss ");
        Quaternion rotation = Quaternion.Euler(currentEnemyJSON.enemyRotation[0], currentEnemyJSON.enemyRotation[1], currentEnemyJSON.enemyRotation[2]);

        print("your name isssssssssssssssss ");
        GameObject          p  = Instantiate(enemyCube, position, rotation) as GameObject;
        EnemyCubeController pc = p.GetComponent <EnemyCubeController>();
        Transform           t  = p.transform.Find("Healthbar Canvas");
        Transform           t1 = t.transform.Find("Player Name");
        Text enemyName         = t1.GetComponent <Text>();

        enemyName.text  = currentEnemyJSON.name;
        pc.isLocalEnemy = true;
        p.name          = currentEnemyJSON.name;
        print("your enemy name is " + currentEnemyJSON.name);
    }
Exemple #2
0
 // Start is called before the first frame update
 void OnAwake()
 {
     Collider[] allOverlappingColliders = Physics.OverlapSphere(transform.position, sphereCollider.radius * transform.localScale.x);
     foreach (Collider coll in allOverlappingColliders)
     {
         if (coll.gameObject.layer != LayerMask.NameToLayer("Player"))
         {
             Rigidbody collRB = coll.GetComponent <Rigidbody>();
             if (collRB != null)
             {
                 EnemyCubeController enemyCubeController = coll.gameObject.GetComponent <EnemyCubeController>();
                 if (enemyCubeController != null)
                 {
                     enemyCubeController.KnockedUp();
                 }
                 collRB.AddExplosionForce(hitForce, transform.position, sphereCollider.radius * transform.localScale.x, upForce, ForceMode.Impulse);
                 Health enemyHealth = coll.gameObject.GetComponent <Health>();
                 enemyHealth.ModifyHealth((int)damage * -1);
             }
         }
     }
     Invoke("DestroySelf", timeToLive);
 }
Exemple #3
0
    void OnOthersEnemy(SocketIOEvent socketIOEvent)
    {
        Debug.Log("Others Enemy is under ganarating.....");
        string     data      = socketIOEvent.data.ToString();
        EnemyJSON  enemyJSON = EnemyJSON.CreateFromJSON(data);
        Vector3    position  = new Vector3(enemyJSON.enemyPosition[0], enemyJSON.enemyPosition[1], enemyJSON.enemyPosition[2]);
        Quaternion rotation  = Quaternion.Euler(enemyJSON.enemyRotation[0], enemyJSON.enemyRotation[1], enemyJSON.enemyRotation[2]);
        GameObject o         = GameObject.Find(enemyJSON.name) as GameObject;

        Debug.Log("enemyJSON : " + data + enemyJSON);
        if (o != null)
        {
            return;
        }
        GameObject oe = Instantiate(enemyCube, position, rotation) as GameObject;

        oe.name = enemyJSON.name;
        EnemyCubeController ecc = oe.GetComponent <EnemyCubeController>();
        Health eh = oe.GetComponent <Health>();

        eh.currentHealth = enemyJSON.health;
        ecc.isLocalEnemy = false;
    }
Exemple #4
0
    private void OnAwake()
    {
        Vector3 offset = new Vector3(0, 0.8f, 0);

        if (Physics.Raycast(new Ray(transform.position + offset, (destination - transform.position)), out RaycastHit hit, 10, hitMask))
        {
            lr.SetPositions(new Vector3[] { transform.position + new Vector3(0, 0.8f, 0), hit.point });
            if (hit.collider.GetComponent <Health>() != null)
            {
                hit.collider.GetComponent <Health>().ModifyHealth((int)damage * -1);
                Rigidbody collRB = hit.collider.GetComponent <Rigidbody>();
                if (collRB != null)
                {
                    EnemyCubeController enemyCubeController = hit.collider.gameObject.GetComponent <EnemyCubeController>();
                    if (enemyCubeController != null)
                    {
                        enemyCubeController.KnockedUp();
                    }
                    collRB.AddForce(hit.normal * hitForce, ForceMode.Impulse);
                    //collRB.AddExplosionForce(hitForce, transform.position, sphereCollider.radius * transform.localScale.x, upForce, ForceMode.Impulse);
                }
            }
        }