Example #1
0
        public void CreateCoral(Coral parent = null)
        {
            Coral coral;

            if (parent == null)
            {
                Debug.Log("START NEW ROOT CORAL");
                coral            = GameObject.Instantiate <Coral>(prefabCoral, LocateNewCoral(), Quaternion.identity);
                coral.depthLevel = 0;
                var     random  = (Vector2)Random.insideUnitCircle.normalized;
                Vector2 gravity = new Vector2();
#if UNITY_EDITOR
                gravity = debugGravity.normalized;
#elif UNITY_ANDROID
                gravity = new Vector2(Input.gyro.gravity.x, Input.gyro.gravity.y).normalized;
#endif
                var up = random + gravity * 2f;
                coral.transform.up = up.normalized;
            }
            else
            {
                // Debug.Log("NEW CORAL BRANCH");
                coral = GameObject.Instantiate <Coral>(prefabCoral, Vector2.zero, Quaternion.identity);
                LocateCoralPart(coral, parent);
                coral.depthLevel = parent.depthLevel + 1;
                coral.parent     = parent;
                parent.DropSeed();
            }
            coral.sea = this;
        }
Example #2
0
        private void LocateCoralPart(Coral coral, Coral parent)
        {
            var parentDirection = Vector2.up;
            var randomVector    = (Vector2)Random.insideUnitCircle.normalized;
            var pos             = parentDirection + randomVector;

            coral.transform.position = pos.normalized * 0.5f;
            coral.transform.SetParent(parent.transform, false);
        }