// Update is called once per frame
    void Update()
    {
        if (readyToSpawn)
        {
            timeSinceSeedCollision += Time.deltaTime;
            if (timeSinceSeedCollision >= spawnDelay)
            {
                readyToSpawn = false;

                var plantGuy = Instantiate(plant, new Vector3(seed.transform.position.x, seed.transform.position.y, seed.transform.position.z), transform.rotation) as Plant;
                plantGuy.GetComponentInChildren <Rigidbody2D>().AddForce(transform.up * spawnForce);
                PlantLocator.GetInstance().SwitchToPlant(plantGuy);
                if (endGame)
                {
                    foreach (var sprite in plantGuy.GetComponentsInChildren <SpriteRenderer>())
                    {
                        sprite.enabled = false;
                    }
                    animation.GetComponent <Animator>().SetBool("play", true);
                    //endGameImage.enabled = true;
                    endGameImage.gameObject.GetComponent <ImageExpander>().enabled = true;
                }
                SeedCounter.IncrementSeedsPlanted();
                Destroy(seed);
                //foreach (var collider in moundColliders)
                //{
                //    collider.enabled = true;
                //}
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (!followThis || followThis != PlantLocator.GetInstance().currentPlant.GetComponentInChildren <GrowthController>().gameObject.transform)
        {
            if (PlantLocator.GetInstance().currentPlant)
            {
                followThis = PlantLocator.GetInstance().currentPlant.GetComponentInChildren <GrowthController>().gameObject.transform;
            }
        }

        if (followThis)
        {
            if (Camera.main.WorldToViewportPoint(followThis.position).x >= rightMostPercentage || Camera.main.WorldToViewportPoint(followThis.position).x <= leftMostPercentage)
            {
                if (transform.position.x > followThis.position.x && transform.position.x <= minXPos)
                {
                    return;
                }
                else if (transform.position.x < followThis.position.x && transform.position.x >= maxXPos)
                {
                    return;
                }

                float newX = Mathf.Lerp(transform.position.x, followThis.position.x, movePerFrame);
                transform.position = new Vector3(newX, transform.position.y, transform.position.z);
            }
        }
    }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     targetObject = PlantLocator.GetInstance().currentPlant;
     if (collision.gameObject.CompareTag(groundTag))
     {
         readyForAttraction = true;
     }
     else if (collision.gameObject.CompareTag(triggerObjectTag) && readyForAttraction && Vector2.Angle(targetObject.transform.up, Vector2.up) >= attractionStopAngle)
     {
         spring.connectedBody = targetObject.GetComponent <Rigidbody2D>();
         spring.enabled       = true;
         readyForAttraction   = false;
     }
 }
 // Start is called before the first frame update
 void Start()
 {
     spring       = GetComponent <SpringJoint2D>();
     targetObject = PlantLocator.GetInstance().currentPlant;
 }