示例#1
0
    private void GeneratePhysicsGOs()
    {
        UOUtility.DestroyChildren(GeneratedPhysicsGO);
        wayPoints.Clear();

        float localSpacing = 0;
        Joint joint        = null;

        for (int i = 0; i < segmentCount; i++)
        {
            GameObject seg = UOUtility.Instantiate(segmentPrefab, GeneratedPhysicsGO.transform);
            seg.transform.Translate(0, 0, localSpacing);
            seg.tag = "Vine";

            Rigidbody segRB = seg.GetComponent <Rigidbody>();
            // we fix the first segment so that the vine won't fall
            if (i == 0)
            {
                segRB.constraints = RigidbodyConstraints.FreezePosition;
                seg.GetComponent <Collider>().enabled = false;            //disable the collider on the first/center of the plant.

                _weed.vinesToPickBeforeDestorying.Enqueue(seg.transform); //store the first physics segment so the player can grab it with IK
            }
            else if (i == Mathf.Ceil(segmentCount / 2))
            {
                //spawn object
                GameObject plantBlock = new GameObject("Generated Plant Block Collider")
                {
                    layer = 11
                };
                plantBlock.transform.position = seg.transform.position;
                plantBlock.transform.SetParent(seg.transform);
                SphereCollider plantBlockCollider = plantBlock.AddComponent <SphereCollider>();
                plantBlockCollider.radius = i * segmentSpacing;
            }
            else if (i + 1 == segmentCount)
            {
                // last segment deals damage to anything that has health
                healthDecrementer = seg.AddComponent <HealthDecrementer>();
                healthDecrementer.damageAmount        = damageAmount;
                healthDecrementer.damageRateInSeconds = damageRateInSeconds;
                healthDecrementer.damagedEnabled      = false;
            }

            // we attach the rigidbody to the joint of the previous segment
            if (joint != null)
            {
                joint.connectedBody = segRB;
            }
            joint = seg.GetComponent <Joint>();

            // we save segments as way points for the spline deformation.
            wayPoints.Add(seg);
            localSpacing += segmentSpacing;
        }
        UOUtility.Destroy(joint);
    }
示例#2
0
 public virtual void HandleCollide(Collider collider, ControllerColliderHit hit)
 {
     if (collider)
     {
         IPoolable obj = collider.GetComponent(typeof(IPoolable)) as IPoolable;
         if (obj != null)
         {
             if (obj is DestroyableObstcle)
             {
                 HandeleCollide(obj as DestroyableObstcle);
             }
             if (obj is PlaceForObstacle)
             {
                 HandeleCollide(obj as PlaceForObstacle, hit);
             }
             if (obj is Rope)
             {
                 HandeleCollide(obj as Rope);
             }
             if (obj is PlaceForDangerZone)
             {
                 HandeleCollide(obj as PlaceForDangerZone);
             }
             if (obj is EnemyAbstract)
             {
                 HandeleCollide(obj as EnemyAbstract, hit);
             }
             if (obj is Bonus)
             {
                 HandeleCollide(obj as Bonus);
             }
         }
         else
         {
             HealthDecrementer health = collider.GetComponent <HealthDecrementer>();
             if (health is HealthDecrementer)
             {
                 if ((health as HealthDecrementer).active)
                 {
                     controller.life.DecreaseHP();
                 }
             }
             FinishArea finish = collider.GetComponent <FinishArea>();
             if (finish != null)
             {
                 Finish(finish);
             }
         }
     }
 }