Esempio n. 1
0
    private void OnTriggerEnter(Collider otherCollider)
    {
        GameObject other = otherCollider.gameObject;

        string[] otherTagSections = GameTags.dissect(other.tag);
        if (GameTags.isOnTeam(other.tag) && otherTagSections[0] == tagSections[0] &&
            otherTagSections[1] == GameTags.Type.WAYPOINT &&
            otherTagSections[2] == tagSections[2])
        {
            arrived = true;
        }
        else
        {
            if (arrived || aggresssive)
            {
                if (GameTags.isOnTeam(other.tag) && otherTagSections[0] != tagSections[0] &&
                    (otherTagSections[1] == GameTags.Type.BUILDING ||
                     otherTagSections[1] == GameTags.Type.UNIT ||
                     otherTagSections[1] == GameTags.Type.PLAYER))
                {
                    targetObjet = other.gameObject;
                }
            }
        }
    }
Esempio n. 2
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. 3
0
    private void CmdspawnBuilding(GameObject building)
    {
        GameObject clickedObject;

        if (didClickObject(out clickedObject))
        {
            string[] tagSections = GameTags.dissect(clickedObject.tag);
            Debug.LogFormat("team: {0} tags: {1}", team, tagSections);
            if (GameTags.isOnTeam(clickedObject.tag) && tagSections[0] == team && tagSections[1] == GameTags.Type.PLACEHOLDER)
            {
                clickedObject.GetComponent <BuildingPlot>().CmdspawnBuilding(building);
                Debug.Log("spawning building");
            }
        }
    }
Esempio n. 4
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. 5
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. 6
0
    // Update is called once per frame
    void Update()
    {
        if (playerStats.inTerritoryMode)
        {
            // Camera Speed
            if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
            {
                speed = fasterer;
            }
            else if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
            {
                speed = normal;
            }

            //Camera Movement
            if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
            {
                tdCam.transform.Translate(new Vector3(speed * Time.deltaTime, 0, 0));
            }
            if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
            {
                tdCam.transform.Translate(new Vector3(-speed * Time.deltaTime, 0, 0));
            }
            if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
            {
                tdCam.transform.Translate(new Vector3(0, -speed * Time.deltaTime, 0));
            }
            if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
            {
                tdCam.transform.Translate(new Vector3(0, speed * Time.deltaTime, 0));
            }
            //Camera Zoom
            float fov = tdCamScript.fieldOfView;
            fov -= Input.GetAxis("Mouse ScrollWheel") * zspeed;
            fov  = Mathf.Clamp(fov, zmin, zmax);
            tdCamScript.fieldOfView  = fov;
            tdCam.transform.rotation = Quaternion.identity;
            tdCam.transform.Rotate(90, 0, 0);
            if (GameTags.dissect(gameObject.tag)[0] == GameTags.Team.RED)
            {
                tdCam.transform.Rotate(0, 0, 180);
            }
        }
    }
Esempio n. 7
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. 8
0
    // Update is called once per frame
    void Update()
    {
        if (!isOnTeam)
        {
            isOnTeam = GameTags.isOnTeam(gameObject.tag);
            if (isOnTeam)
            {
                team = GameTags.dissect(gameObject.tag)[0];
            }
        }
        else
        {
            if (playerStats.inTerritoryMode)
            {
                if (Input.GetKeyDown(KeyCode.Alpha0))
                {
                    mouseState = MouseState.EMPTY;
                    Debug.Log("set mouse to empty");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    mouseState = MouseState.ATTACK_WAYPOINT;
                    Debug.Log("set mouse to attack waypoint");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    mouseState = MouseState.DEFENSE_WAYPOINT;
                    Debug.Log("set mouse to defense waypoint");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    mouseState = MouseState.SUPPORT_WAYPOINT;
                    Debug.Log("set mouse to support waypoint");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha4))
                {
                    mouseState = MouseState.SCOUT__WAYPOINT;
                    Debug.Log("set mouse to scout waypoint");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha5))
                {
                    mouseState = MouseState.SPAWN_ATTACK;
                    Debug.Log("set mouse to attack building");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha6))
                {
                    mouseState = MouseState.SPAWN_DEFENSE;
                    Debug.Log("set mouse to defense building");
                }
                else if (Input.GetKeyDown(KeyCode.Alpha7))
                {
                    mouseState = MouseState.SPAWN_SUPPORT;
                    Debug.Log("set mouse to support building");
                }

                //if (Input.GetMouseButtonDown(0)) {
                if (Input.GetKeyDown(KeyCode.Q))
                {
                    Debug.Log("clicked mouse button");
                    bool aggressive = Input.GetKey(KeyCode.LeftShift);
                    if (aggressive)
                    {
                        Debug.Log("set aggressive");
                    }
                    switch (mouseState)
                    {
                    case MouseState.EMPTY: {
                        // spawn units when clicking on a building
                        // if 0 == team
                        // if 1 == building
                        // if 2 == spawn or HQ
                        // call spawn
                        GameObject clickedObject;
                        if (didClickObject(out clickedObject))
                        {
                            Debug.LogFormat("clicked on obj {0} with tag {1}", clickedObject.name,
                                            clickedObject.tag);
                            string[] tagSections = GameTags.dissect(clickedObject.tag);
                            if (GameTags.isOnTeam(clickedObject.tag) && tagSections[0] == team && tagSections[1] == GameTags.Type.BUILDING &&
                                (tagSections[2] == GameTags.BuildingClass.SPAWN || tagSections[2] == GameTags.BuildingClass.HQ))
                            {
                                // TODO: check for resources here
                                Debug.Log("Spawning units");
                                clickedObject.GetComponent <UnitSpawner>().CmdspawnUnit();
                            }
                        }
                        break;
                    }

                    case MouseState.ATTACK_WAYPOINT: {
                        // set waypoint for attack units
                        CmdmoveWaypoint(GameTags.UnitClass.ATTACK, aggressive);
                        Debug.Log("Set attack waypoint");
                        break;
                    }

                    case MouseState.DEFENSE_WAYPOINT: {
                        // set waypoint for defense units
                        CmdmoveWaypoint(GameTags.UnitClass.DEFENSE, aggressive);
                        Debug.Log("Set defense waypoint");
                        break;
                    }

                    case MouseState.SUPPORT_WAYPOINT: {
                        // set waypoint for support units
                        CmdmoveWaypoint(GameTags.UnitClass.SUPPORT, aggressive);
                        Debug.Log("Set support waypoint");
                        break;
                    }

                    case MouseState.SCOUT__WAYPOINT: {
                        // set waypoint for scout units
                        CmdmoveWaypoint(GameTags.UnitClass.SCOUT, aggressive);
                        Debug.Log("Set scout waypoint");
                        break;
                    }

                    case MouseState.SPAWN_ATTACK: {
                        // spawn an attack building
                        if (team == GameTags.Team.RED)
                        {
                            CmdspawnBuilding(redAttackBuildingPrefab);
                            Debug.Log("Spawn red attack building");
                        }
                        else
                        {
                            CmdspawnBuilding(blueAttackBuildingPrefab);
                            Debug.Log("Spawn blue attack building");
                        }
                        break;
                    }

                    case MouseState.SPAWN_DEFENSE: {
                        // spawn an attack building
                        if (team == GameTags.Team.RED)
                        {
                            CmdspawnBuilding(redDefenseBuildingPrefab);
                            Debug.Log("Spawn red defense building");
                        }
                        else
                        {
                            CmdspawnBuilding(blueDefenseBuildingPrefab);
                            Debug.Log("Spawn blue defense building");
                        }
                        break;
                    }

                    case MouseState.SPAWN_SUPPORT: {
                        // spawn an attack building
                        if (team == GameTags.Team.RED)
                        {
                            CmdspawnBuilding(redSupportBuildingPrefab);
                            Debug.Log("Spawn red support building");
                        }
                        else
                        {
                            CmdspawnBuilding(blueSupportBuildingPrefab);
                            Debug.Log("Spawn blue support building");
                        }
                        break;
                    }
                    }
                }
            }
            else
            {
                if (Input.GetKeyDown(KeyCode.Q))
                {
                    switch (mouseState)
                    {
                    case MouseState.ATTACK_WAYPOINT: {
                        // set waypoint for attack units
                        CmdmoveWaypoint(GameTags.UnitClass.ATTACK, true);
                        break;
                    }

                    case MouseState.DEFENSE_WAYPOINT: {
                        // set waypoint for defense units
                        CmdmoveWaypoint(GameTags.UnitClass.DEFENSE, true);
                        break;
                    }

                    case MouseState.SUPPORT_WAYPOINT: {
                        // set waypoint for support units
                        CmdmoveWaypoint(GameTags.UnitClass.SUPPORT, true);
                        break;
                    }

                    case MouseState.SCOUT__WAYPOINT: {
                        // set waypoint for scout units
                        CmdmoveWaypoint(GameTags.UnitClass.SCOUT, true);
                        break;
                    }
                    }
                }
            }
        }
    }