Пример #1
0
    // Update is called once per frame
    void Update()
    {
        InputUpdates [PlayerInputState] ();
        if (Input.GetMouseButtonDown(0))
        {
            if (ActiveGrapplingHook != null)
            {
                GrapplingState = E_GrapplingState.Detached;
                if (PlayerInputState == E_PlayerInputState.Swinging)
                {
                    PlayerInputState = E_PlayerInputState.Free;
                }
                GameObject.Destroy(ActiveGrapplingHook);
            }
            Vector3 v3     = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            float   vx     = v3.x - body.position.x;
            float   vy     = v3.y - body.position.y;
            double  vangle = Trig.GetAngle(new Vector2(vx, vy));
            ActiveGrapplingHook = Instantiate(GrapplingHookBase, new Vector3(body.position.x + Mathf.Cos((float)vangle), body.position.y + Mathf.Sin((float)vangle), 0), new Quaternion()).gameObject;
            ActiveGrapplingHook.GetComponent <GrapplingHookController> ().SetPendulum(this);
            ActiveGrapplingHook.SetActive(true);
            ActiveGrapplingHook.GetComponent <Rigidbody2D>().velocity = new Vector2(50 * Mathf.Cos((float)vangle), 50 * Mathf.Sin((float)vangle));
        }

        if ((Input.GetMouseButtonDown(1)) && (ActiveGrapplingHook != null))
        {
            GrapplingState = E_GrapplingState.Detached;
            GameObject.Destroy(ActiveGrapplingHook);
            ActiveGrapplingHook = null;
            if (PlayerInputState == E_PlayerInputState.Swinging)
            {
                PlayerInputState = E_PlayerInputState.Free;
            }
        }
    }
Пример #2
0
 public void CreateAnchor()
 {
     GrapplingState = E_GrapplingState.Attached;
     if (PlayerInputState == E_PlayerInputState.Free)
     {
         PlayerInputState = E_PlayerInputState.Swinging;
     }
 }
Пример #3
0
 void LeftGround()
 {
     Debug.Log("Left Ground");
     if (IsAttached())
     {
         PlayerInputState = E_PlayerInputState.Swinging;
     }
     else if (GrapplingState == E_GrapplingState.Detached)
     {
         PlayerInputState = E_PlayerInputState.Free;
     }
 }
Пример #4
0
    void FixedUpdate()
    {
        RaycastHit2D[] lineGround  = Physics2D.RaycastAll(new Vector2(body.position.x, body.position.y), Vector2.down);
        RaycastHit2D   nearestTile = lineGround[0];

        bool found = false;

        foreach (RaycastHit2D obj in lineGround)
        {
            if (!Manager.ObjectLog.ContainsKey(obj.collider.gameObject))
            {
                Debug.Log("Object not found");
            }
            else if (Manager.ObjectLog [obj.collider.gameObject].GetType() == typeof(TileController))
            {
                if (found == false)
                {
                    nearestTile = obj;
                    found       = true;
                }
                else
                {
                    if (obj.distance < nearestTile.distance)
                    {
                        nearestTile = obj;
                    }
                }
            }
        }
        if (found)
        {
            if ((nearestTile.distance > 0.6) && (PlayerInputState == E_PlayerInputState.Ground))
            {
                LeftGround();
            }
            else if ((nearestTile.distance <= 0.6) && (PlayerInputState != E_PlayerInputState.Ground))
            {
                Debug.Log("Hit Ground");
                PlayerInputState = E_PlayerInputState.Ground;
            }
        }
        else if (PlayerInputState == E_PlayerInputState.Ground)
        {
            LeftGround();
        }
        FixedUpdates [PlayerInputState] ();
    }