Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        lastingTime -= Time.deltaTime;

        if (lastingTime <= 1.0f)
        {
            // update transparent
            Color tmp = renderer.color;
            tmp.a          = lastingTime;
            renderer.color = tmp;

            tmp   = shadowRenderer.color;
            tmp.a = lastingTime;
            if (shadowRenderer.color.a > tmp.a)
            {
                shadowRenderer.color = tmp;
            }


            if (lastingTime <= 0.0f)
            {
                CurrentScene.Instance().UnregisterFood(transform);
                Destroy(gameObject);
            }
        }
    }
Ejemplo n.º 2
0
    private void Start()
    {
        renderer       = transform.GetChild(0).GetComponent <SpriteRenderer>();
        shadowRenderer = transform.GetChild(1).GetComponent <SpriteRenderer>();

        CurrentScene.Instance().RegisterNewFood(transform);
    }
Ejemplo n.º 3
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Vector2 mousePositionInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         if (CurrentScene.Instance().GetCollider().ClosestPoint(mousePositionInWorld) == mousePositionInWorld)
         {
             Instantiate(foodToSpawn, mousePositionInWorld, Quaternion.identity);
         }
     }
 }
Ejemplo n.º 4
0
    private void Move()
    {
        Vector2 newPos = transform.position;

        newPos += moveDirection * moveSpeed * Time.deltaTime;

        SetFlip(moveDirection.x);

        if (CurrentScene.Instance().GetCollider().ClosestPoint(newPos) == newPos)
        {
            transform.DOMove(newPos, Time.deltaTime);
        }
        else
        {
            //reverse move
            moveDirection = -moveDirection;
        }
    }
Ejemplo n.º 5
0
 private void FindFood()
 {
     if (CurrentScene.Instance().GetRegisteredFoodNumber() > 0)
     {
         targetFood = CurrentScene.Instance().GetNearestFood(transform.position);
         Vector2 targetPos = targetFood.position;
         if (cell.GetComponent <Collider2D>().ClosestPoint(targetPos) == targetPos)
         {
             status = AI.Status.eat;
         }
         else
         {
             status = AI.Status.chase;
         }
     }
     else
     {
         status = AI.Status.wander;
     }
 }
Ejemplo n.º 6
0
 public void Consume()
 {
     CurrentScene.Instance().UnregisterFood(transform);
     Destroy(gameObject);
 }