예제 #1
0
    void Start()
    {
        anim = gameObject.GetComponent <Animator> ();
        anim.SetFloat("IdleAnim", orientation);
        this.gameObject.GetComponent <Rigidbody2D> ().gravityScale = TransformFormat.getYVel(1f);

        CheckMove();
    }
예제 #2
0
    void OnTriggerStay2D(Collider2D col)
    {
        if (col.name == "MainChar")
        {
            col.attachedRigidbody.isKinematic = true;

            rigid = col.attachedRigidbody;
        }

        if (Input.GetButton("MoveUp") && col.name == "MainChar")
        {
            col.transform.Translate(TransformFormat.getTransVel(Vector3.up * 0.04f));
        }
        if (Input.GetButton("MoveDown") && col.name == "LadderCollider")
        {
            col.transform.parent.transform.Translate(TransformFormat.getTransVel(Vector3.down * 0.04f));
        }
    }
예제 #3
0
    void Move()
    {
        if (Input.GetButton("MoveLeft"))
        {
            if (!isHit)
            {
                transform.Translate(TransformFormat.getTransVel(Vector3.left * speed));
                anim.SetBool("MoveLeft", true);
            }
            dir = Vector3.left;
        }
        if (Input.GetButton("MoveRight"))
        {
            if (!isHit)
            {
                transform.Translate(TransformFormat.getTransVel(Vector3.right * speed));
                anim.SetBool("MoveRight", true);
            }
            dir = Vector3.right;
        }
        if (Input.GetButton("MoveLeft") && Input.GetButton("MoveRight"))
        {
            anim.SetBool("MoveLeft", false);
            anim.SetBool("MoveRight", false);
        }

        if (Input.GetButtonUp("MoveLeft") || isHit)
        {
            anim.SetBool("MoveLeft", false);
            if (dir == Vector3.left)
            {
                anim.SetFloat("IdleAnim", 0f);
            }
        }

        if (Input.GetButtonUp("MoveRight") || isHit)
        {
            anim.SetBool("MoveRight", false);
            if (dir == Vector3.right)
            {
                anim.SetFloat("IdleAnim", 1f);
            }
        }
    }
예제 #4
0
    void Update()
    {
        Debug.DrawRay(transform.position, dir * Mathf.Infinity, Color.red, 0f);
        hit  = Physics2D.Raycast(transform.position, dir, TransformFormat.getXVel(1f));
        spot = Physics2D.Raycast(transform.position, dir, Mathf.Infinity);

        if (hit && (hit.collider.tag == "wall" /*|| hit.collider.tag == "doorway"*/ || hit.collider.name == "MainChar"))
        {
            isHit = true;
        }
        else
        {
            isHit = false;
        }

        if (spot && spot.collider.name == "MainChar")
        {
            guardHandler.Enable();
        }
    }
예제 #5
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.B))
        {
            saveScript.SaveGame();
        }

        Debug.DrawRay(transform.position, dir * TransformFormat.getXVel(1f), Color.red, 0f);
        hit = Physics2D.Raycast(transform.position, dir, TransformFormat.getXVel(1f), 13);



        if (hit && (hit.collider.tag == "wall" /*|| hit.collider.tag == "doorway"*/))
        {
            isHit = true;
        }
        else
        {
            isHit = false;
        }
        Move();
    }
예제 #6
0
    void Start()
    {
        anim.SetFloat("IdleAnim", orientation);
        this.gameObject.GetComponent <Rigidbody2D> ().gravityScale = TransformFormat.getYVel(1f);

        if (PlayerPrefs.GetString("Command") == "save")
        {
            saveScript.SaveGame();
        }
        if (PlayerPrefs.GetString("Command") == "load")
        {
            saveScript.LoadGame();
        }

        if (PlayerPrefs.GetString("Position") == "begin" || PlayerPrefs.GetString("Command") != "load")
        {
            this.transform.position = GameObject.Find("SpawnPosition").transform.position;
        }

        PlayerPrefs.DeleteKey("Position");
        PlayerPrefs.DeleteKey("Command");
    }
예제 #7
0
    public IEnumerator MoveLeft(float waitT)
    {
        orientation = 0;
        yield return(new WaitForSeconds(waitT));

        dir   = Vector3.left;
        isHit = false;

        while (!isHit)
        {
            transform.Translate(TransformFormat.getTransVel(Vector3.left * speed));
            anim.SetBool("MoveLeft", true);
            yield return(null);
        }

        if (isHit)
        {
            StopCoroutine("MoveLeft");
            anim.SetBool("MoveLeft", false);
            anim.SetFloat("IdleAnim", 0f);

            StartCoroutine("MoveRight", waitTimetoTurn);
        }
    }