コード例 #1
0
ファイル: moveObjectsOnTop.cs プロジェクト: jabackf/Blubber2
    public void checkNewCollision(Collision2D other)
    {
        if (myType != platformType.disabled)
        {
            Rigidbody2D rb = other.gameObject.GetComponent <Rigidbody2D>();
            if (rb != null)
            {
                Debug.Log(other.gameObject.name + " new col check1 - velocity: " + rb.velocity.y);
                if (!rb.isKinematic && rb.simulated && rb.IsAwake() && other.gameObject.transform.position.y > gameObject.transform.position.y)// && rb.velocity.y <= 0)
                {
                    Debug.Log(other.gameObject.name + " new col check2, does it need script?");
                    moveObjectsOnTop script = other.gameObject.GetComponent <moveObjectsOnTop>();
                    if (script == null)
                    {
                        Debug.Log(other.gameObject.name + " is getting the script from " + gameObject.name);
                        script = other.gameObject.AddComponent(typeof(moveObjectsOnTop)) as moveObjectsOnTop;
                        script.setAddedDynamically(true);
                        script.myType = platformType.moveWithPlatform;
                        if (myType == platformType.moveWithPlatform)
                        {
                            Debug.Log(other.gameObject.name + " is getting childed to " + gameObject.name);
                            parentEntry e = new parentEntry();
                            e.previous   = other.gameObject.transform.parent;
                            e.gameObject = other.gameObject;
                            parents.Add(e);

                            other.gameObject.transform.parent = gameObject.transform;
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
ファイル: moveObjectsOnTop.cs プロジェクト: jabackf/Blubber2
    private void OnCollisionExit2D(Collision2D other)
    {
        foreach (parentEntry e in parents)
        {
            if (e.gameObject == other.gameObject)
            {
                e.gameObject.transform.parent = e.previous;
                Debug.Log(e.gameObject.name + " is getting un-childed from" + gameObject.name);
            }
        }
        parents.RemoveAll(parentEntry => parentEntry.gameObject == other.gameObject);

        if (other.gameObject.transform.position.y > gameObject.transform.position.y)
        {
            moveObjectsOnTop script = other.gameObject.GetComponent <moveObjectsOnTop>();
            if (script != null)
            {
                if (script.addedDynamically)
                {
                    script.resetParents();
                    Destroy(script);
                    Debug.Log(other.gameObject.name + " is losing its script from " + gameObject.name);
                }
            }
        }
    }
コード例 #3
0
ファイル: moveObjectsOnTop.cs プロジェクト: jabackf/Blubber2
    public void resetParents()
    {
        Debug.Log(gameObject.name + " is having all parents reset");
        foreach (parentEntry e in parents)
        {
            e.gameObject.transform.parent = e.previous;
            moveObjectsOnTop script = e.gameObject.GetComponent <moveObjectsOnTop>();
            if (script != null)
            {
                if (script.addedDynamically)
                {
                    script.resetParents();
                }
            }
        }

        parents.Clear();
    }