Example #1
0
    void RTSClick()
    {
        Ray        ray = Camera.main.ScreenPointToRay(mousePosition1);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            Object.Destroy(dest);
            dest = new GameObject();
            dest.transform.position = hit.point;
            foreach (GameObject go in selectedObjects)
            {
                BasicSoldier bs = go.GetComponent <BasicSoldier>();
                if (bs.inCover)
                {
                    if (bs.state == BasicSoldier.AIStates.defensive)
                    {
                        bs.goal.gameObject.tag = "CoverSpot";
                    }
                    else
                    {
                        bs.goal.gameObject.tag = "AmbushSpot";
                    }
                    bs.inCover = false;
                }
                bs.goal  = dest.transform;
                bs.state = BasicSoldier.AIStates.passive;
            }
        }
    }
Example #2
0
    private void fire()
    {
        if (fpsAni.isPlaying)
        {
            return;
        }
        FPSAni("fireWeapon");
        ammoCnt -= 1;
        flame.Emit(1);
        shotAudio.Play();
        Vector3    direction = playerCam.transform.TransformDirection(Vector3.forward);
        RaycastHit hit;

        if (Physics.Raycast(playerCam.transform.position, direction, out hit, 300))
        {
            Vector4 dmgInfo = new Vector4();
            dmgInfo.x = hit.normal.x;
            dmgInfo.y = hit.normal.y;
            dmgInfo.z = hit.normal.z;
            dmgInfo.w = damage;
            Debug.DrawLine(playerCam.transform.position, hit.point, Color.cyan);
            Debug.Log("firing shot");
            //hit.collider.SendMessageUpwards("applyDamage", dmgInfo, SendMessageOptions.DontRequireReceiver);
            BasicSoldier bs = hit.collider.gameObject.GetComponent <BasicSoldier>();
            Debug.Log("HITTING " + hit.collider.gameObject.name);
            if (bs)
            {
                Debug.Log("Client found bs");
                CmdSendShot(bs.GetComponent <NetworkIdentity>().netId, dmgInfo);
            }
        }
    }
Example #3
0
    void Update()
    {
        // If we press the left mouse button, save mouse location and begin selection
        if (Input.GetMouseButtonDown(0))
        {
            if (!isSelecting)
            {
                foreach (GameObject go in selectedObjects)
                {
                    go.transform.Find("Quad").gameObject.SetActive(false);
                }
            }
            selectedObjects.Clear();
            isSelecting    = true;
            mousePosition1 = Input.mousePosition;
        }
        // If we let go of the left mouse button, end selection
        if (Input.GetMouseButtonUp(0))
        {
            allUnits = GameObject.FindGameObjectsWithTag("EnemyUnit");
            //Debug.Log(allUnits.Length);
            isSelecting = false;
            Vector3 mousePositionT = Input.mousePosition;
            mousePosition1.y = Screen.height - mousePosition1.y;
            mousePositionT.y = Screen.height - mousePositionT.y;
            Rect rec = Utils.GetScreenRect(mousePosition1, mousePositionT);
            foreach (GameObject go in allUnits)
            {
                Camera  cam       = GetComponent <Camera>();
                Vector3 screenPos = cam.WorldToScreenPoint(go.transform.position);
                screenPos.z = 0;
                if (rec.Contains(screenPos))
                {
                    go.transform.Find("Quad").gameObject.SetActive(true);
                    selectedObjects.Add(go);
                }
            }
            //Debug.Log(selectedObjects.Count);
        }

        if (Input.GetMouseButtonDown(1))
        {
            mousePosition1 = Input.mousePosition;
            RTSClick();
        }

        if (Input.GetKey(KeyCode.Alpha1))
        {
            foreach (GameObject go in selectedObjects)
            {
                BasicSoldier bs = go.GetComponent <BasicSoldier>();
                bs.state        = BasicSoldier.AIStates.passive;
                bs.changedState = true;
            }
        }

        if (Input.GetKey(KeyCode.Alpha2))
        {
            foreach (GameObject go in selectedObjects)
            {
                BasicSoldier bs = go.GetComponent <BasicSoldier>();
                bs.state        = BasicSoldier.AIStates.aggressive;
                bs.changedState = true;
            }
        }

        if (Input.GetKey(KeyCode.Alpha3))
        {
            foreach (GameObject go in selectedObjects)
            {
                BasicSoldier bs = go.GetComponent <BasicSoldier>();
                bs.state        = BasicSoldier.AIStates.defensive;
                bs.changedState = true;
            }
        }
    }