Beispiel #1
0
    void OnCollisionEnter2D(Collision2D col)
    {
        GameObject obj = col.gameObject;

        if (obj.CompareTag("Player"))
        {
            float   damage  = col.relativeVelocity.magnitude * collisionDamageScale;
            Postcat postcat = obj.GetComponent <Postcat>();
            postcat.ApplyDamage(damage);

            Vector3 playerDir =
                (obj.transform.position - transform.position).normalized;

            float angle = Vector3.Angle(Vector3.left, playerDir);

            // Sound
            FindObjectOfType <AudioManager>().Play("hitAsteroid");

            if (angle >= 30.0f && angle <= 100.0f)
            {
                // Debug.Log("Jump");
                postcat.Jump();
            }
            else if (angle < 30.0f || angle > 100.0f)
            {
                // Debug.Log("Crash");
                postcat.Crash();
            }
        }
    }
Beispiel #2
0
    void OnTriggerEnter2D(Collider2D col)
    {
        GameObject obj = col.gameObject;

        if (obj.CompareTag("Player"))
        {
            Postcat postcat = obj.GetComponent <Postcat>();

            Transform cargoTransform = obj.transform.GetChild(1).GetComponent <Rope>().end;

            float cargoHealth = 0;

            if (cargoTransform != null)
            {
                cargoHealth = cargoTransform.GetComponent <Cargo>().health;
            }

            Transform checkpointRoot = GameObject.Find("CheckpointRoot").transform;

            gameController.StageCleared(
                postcat.fuel,
                cargoHealth,
                checkpointRoot.transform.position.x
                );

            Destroy(obj);
        }
        else if (obj.CompareTag("Cargo") || obj.CompareTag("Rope"))
        {
            Destroy(obj);
        }
    }
Beispiel #3
0
    public IEnumerator InstantiatePostCatWithPackage()
    {
        GameObject respawn = GameObject.FindGameObjectWithTag("Respawn");

        postcatObj = Instantiate(
            postcatPrefabWithCargo,
            respawn.transform.position,
            respawn.transform.rotation).gameObject;

        // Get fuel from station.
        Postcat postcat = postcatObj.GetComponentInChildren <Postcat>();

        postcat.fuel = 100 + gameState.Take();

        // Set target for main camera.
        Camera.main.GetComponent <CameraController>().target = postcatObj.transform.GetChild(0);

        yield return(new WaitForSeconds(0.1f));

        // Push Postcat away from the station.
        foreach (Rigidbody2D rb in postcatObj.GetComponentsInChildren <Rigidbody2D>())
        {
            rb.AddForce(Vector3.right * 10.0f, ForceMode2D.Impulse);
        }
    }
Beispiel #4
0
    void OnTriggerEnter2D(Collider2D col)
    {
        GameObject obj = col.gameObject;

        if (obj.CompareTag("Player"))
        {
            Postcat postcat = obj.GetComponent <Postcat>();

            postcat.Refuel(fuel);

            animator.SetTrigger("Take");
        }
    }
Beispiel #5
0
    // Collider that pulls objects inside station.
    void OnTriggerStay2D(Collider2D col)
    {
        GameObject obj = col.gameObject;

        if (obj.CompareTag("Player") || obj.CompareTag("Cargo"))
        {
            Postcat postcat = obj.GetComponent <Postcat>();

            // Suck Player into Station
            Vector3 dir = transform.position - obj.transform.position;
            obj.GetComponent <Rigidbody2D>().AddForce(dir * pullForce);
        }


        //TODO: возможно тоже играт что-то ...
    }