コード例 #1
0
    void OnTriggerEnter(Collider collider)
    {
        Atom atom = collider.gameObject.GetComponent <Atom>();

        if (atom != null && Arranger.HasEmptyLinks && atom.Arranger.HasEmptyLinks)
        {
            System.Random random = new System.Random();
            P = random.Next();
            while (P == atom.P)
            {
                P = random.Next();
            }
            if (P > atom.P)
            {
                Debug.Log($"{name} linked with {atom.name}");
                P = null;
                Arranger.Link(atom.transform);
                atom.RotateTowards(transform);
            }
            P      = null;
            moving = false;
            return;
        }

        GameObject col = collider.gameObject;

        if (col.CompareTag("Wall"))
        {
            Transform wall = col.transform;
            float     x    = col.name.Equals("Right") || col.name.Equals("Left") ? -Movement.x : Movement.x;
            float     y    = col.name.Equals("Top") || col.name.Equals("Bottom") ? -Movement.y : Movement.y;
            float     z    = col.name.Equals("Back") || col.name.Equals("Front") ? -Movement.z : Movement.z;

            Movement = new Vector3(x, y, z);
        }
    }