Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (weaponOn)
        {
            vectorPlayer = playerController.transform.position;
            // weaponOnPlayer.transform.LookAt(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10)));

            if (Input.GetMouseButtonDown(0) && Time.time > nextmelee)
            {
                nextmelee = Time.time + meleerate;
                swing     = true;
            }

            if (swing == true && timer > 0)
            {
                //turn on trigger
                GameObject.FindGameObjectWithTag(GameTags.create(GameTags.dissect(gameObject.tag)[0], GameTags.Type.WEAPON, GameTags.WeaponClass.MELEE)).GetComponent <Collider>().enabled = true;
                weaponOnPlayer.transform.RotateAround(vectorPlayer, Vector3.down, Time.deltaTime * smooth);
                timer -= Time.deltaTime;
            }

            else
            {
                swing = false;
                weaponOnPlayer.transform.position = vectorWeaponStart.transform.position;
                weaponOnPlayer.transform.rotation = gameObject.transform.rotation;
                weaponOnPlayer.transform.Rotate(90, 15, 0);
                // disable collider
                GameObject.FindGameObjectWithTag(GameTags.create(GameTags.dissect(gameObject.tag)[0], GameTags.Type.WEAPON, GameTags.WeaponClass.MELEE)).GetComponent <Collider>().enabled = false;
                timer = 0.5f;
            }
        }
    }
Esempio n. 2
0
    private void CmdmoveWaypoint(string unitClass, bool aggressive)
    {
        Debug.LogFormat("Moving waypoint {0} {1}", team, unitClass);
        Vector3 newPos;

        if (didClick(out newPos))
        {
            string     waypointTag = GameTags.create(team, GameTags.Type.WAYPOINT, unitClass);
            GameObject waypoint    = GameObject.FindGameObjectWithTag(waypointTag);
            waypoint.transform.position = newPos;
        }
        // TODO: set aggressive or not
    }
Esempio n. 3
0
    public void CmdspawnUnit()
    {
        string     newTag = GameTags.create(GameTags.dissect(gameObject.tag)[0], GameTags.Type.PLAYER);
        GameObject player = GameObject.FindGameObjectWithTag(newTag);

        for (int i = 0; i < MAX_UNITS; ++i)
        {
            if (spawnedUnits[i] == null)
            {
                spawnedUnits[i] = Instantiate(unitPrefab, gameObject.transform.GetChild(0).transform.position, Quaternion.identity) as GameObject;
                // NetworkServer.SpawnWithClientAuthority(spawnedUnits[i],player);
                NetworkServer.Spawn(spawnedUnits[i]);
                break;
            }
        }
    }
Esempio n. 4
0
    public void CmdspawnBuilding(GameObject building)
    {
        if (!active)
        {
            string     newTag = GameTags.create(GameTags.dissect(gameObject.tag)[0], GameTags.Type.PLAYER);
            GameObject player = GameObject.FindGameObjectWithTag(newTag);

            Quaternion buildingRotation = Quaternion.identity;
            this.building = (GameObject)Instantiate(building, gameObject.transform.position, buildingRotation);
            if (GameTags.dissect(gameObject.tag)[0] == GameTags.Team.RED)
            {
                this.building.transform.Rotate(0, 180, 0);
            }
            // NetworkServer.SpawnWithClientAuthority(this.building, player);
            NetworkServer.Spawn(this.building);
            active = true;
        }
    }
Esempio n. 5
0
 // Update is called once per frame
 void Update()
 {
     if (!isOnTeam)
     {
         isOnTeam = GameTags.isOnTeam(gameObject.tag);
         if (isOnTeam)
         {
             tagSections    = GameTags.dissect(gameObject.tag);
             targetWaypoint = GameObject.FindGameObjectWithTag(GameTags.create(tagSections[0], GameTags.Type.WAYPOINT, tagSections[2]));
             Debug.LogFormat("Unit {0} has waypoint {1}", gameObject.tag, targetWaypoint.tag);
             if (targetWaypoint != null)
             {
                 controller.SetTarget(targetWaypoint.transform);
             }
         }
     }
     else
     {
         if (tagSections == null)
         {
             tagSections = GameTags.dissect(gameObject.tag);
         }
         if (arrived && targetObjet == null)
         {
             controller.SetTarget(gameObject.transform);
         }
         else if (targetObjet != null)
         {
             controller.SetTarget(targetObjet.transform);
         }
         else
         {
             controller.SetTarget(targetWaypoint.transform);
         }
     }
 }
Esempio n. 6
0
    // Update is called once per frame
    void Update()
    {
        if (!playersConnected)
        {
            redPlayer        = GameObject.FindWithTag("RED_PLAYER");
            bluePlayer       = GameObject.FindWithTag("BLUE_PLAYER");
            playersConnected = redPlayer != null && bluePlayer != null;

            //Debug.Log("trying to find all players");
        }
        if (playersConnected)
        {
            if (!setBuildings)
            {
                Debug.Log("Updating buildings");
                foreach (NetworkConnection conn in NetworkServer.connections)
                {
                    Debug.LogFormat("current connection: {0}", conn);
                    if (conn.hostId != -1)
                    {
                        Debug.Log("Not the host :3");
                        foreach (GameObject building in GameObject.FindGameObjectsWithTag(GameTags.create(GameTags.Team.BLUE, GameTags.Type.PLACEHOLDER, GameTags.Type.BUILDING)))
                        {
                            Debug.LogFormat("setting authority for building {0}", building);
                            Debug.LogFormat("current building authority: {0}", building.GetComponent <NetworkIdentity>().clientAuthorityOwner);
                            building.GetComponent <NetworkIdentity>().AssignClientAuthority(conn);
                            Debug.LogFormat("new building authority: {0}", building.GetComponent <NetworkIdentity>().clientAuthorityOwner);
                        }
                    }
                }
                setBuildings = true;
            }
            //checking if the hq and building of one player is destroyed
            if (redPlayer == null)
            {
                //making the local host winner
                blueWin = true;
                redWin  = false;
                changeScene();
            }
            else if (bluePlayer == null)
            {
                //makeing the other player winner

                blueWin = false;
                redWin  = true;
                changeScene();
            }
        }

        // redHQ = GameObject.FindWithTag("RED_BUILDING_HQ");
        // blueHQ = GameObject.FindWithTag("BLUE_BUILDING_HQ");
    }