Пример #1
0
    public void SetPossessed(Possesable target)
    {
        if (possesing != null)
        {
            possesing.isPossessed = false;
        }
        target.isPossessed = true;
        possesing          = target;

        //Spawn possess target
        if (target.GetComponent <CameraController>() == null)  //if not camera
        {
            possessCursor = Instantiate(Resources.Load("possessCursor") as GameObject);
            possessCursor.GetComponent <CursorBob>().following = possesing.transform;
        }
        else if (possessCursor != null)     //otherwise if we are possessing the camera, destroy the cursor
        {
            Destroy(possessCursor);
            possessCursor = null;
        }
    }
Пример #2
0
    public override void PossessedBehavior()
    {
        //Defualt RTS camera controls

        //Pan
        //InputManager im = Global.inputManager;
        Vector2 pan_inp = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized;

        if (pan_inp != Vector2.zero)
        {
            Vector3 pos = transform.position;

            //move in direction cam is facing
            Vector3 forward = new Vector3(cam.transform.forward.x, 0, cam.transform.forward.z).normalized;
            pos += forward * pan_inp.y * panSpeed * Time.deltaTime;
            pos += cam.transform.right * pan_inp.x * panSpeed * Time.deltaTime;

            transform.position = pos;
        }


        //Click on screen, if there is a possessable object, focus on it
        if (Input.GetMouseButtonDown(0))
        {
            //first find position on output screen and map it to capture cam
            //Debug.Log(Global.screenManager.GetScreenClick());
            Vector2 clickPos = Global.screenManager.GetScreenClick();
            Vector3 origin   = cam.transform.position;
            origin += cam.transform.up * clickPos.y;
            origin += cam.transform.right * clickPos.x;

            //ray cast and take the first possessable object we hit

            Ray ray = new Ray(origin, cam.transform.forward);
            Debug.DrawRay(origin, cam.transform.forward * 100, Color.red, 2);

            RaycastHit[] hits = Physics.RaycastAll(ray);
            Possesable   p    = null;
            if (hits.Length > 0)
            {
                for (int i = 0; i < hits.Length; i++)
                {
                    RaycastHit hit = hits[i];
                    p = hit.transform.gameObject.GetComponent <Possesable>();
                    if (p != null)   //grab first object that is possessable
                    {
                        Debug.Log("HIT!");
                        break;
                    }
                }
            }

            //if possessable is not null, that means we hit something
            if (p != null)   //set it as our focus
            {
                focus = p.transform;

                SoundPlayer.quickStart("Sounds/camFocus");
            }
            else     //if we dont hit anything we unfocus our focus
            {
                focus = null;

                SoundPlayer.quickStart("Sounds/camUnfocus");
            }
        }

        if (Input.GetKeyDown(KeyCode.B))
        {
            focus = Global.pizzaTruck.transform;
        }

        //possess key

        if (Input.GetKeyDown(KeyCode.Space) && focus != null)   //we can only possess something if we are focused on it
        {
            Assert.IsNotNull(focus.gameObject.GetComponent <Possesable>());

            Global.possesor.SetPossessed(focus.gameObject.GetComponent <Possesable>());

            SoundPlayer.quickStart("Sounds/possess2", 0.2f);
        }
    }