Example #1
0
    public void eatFood(Vector3 snakeHeadPosition, SpawnEnemyAI se)
    {
        positionRecord snakeHeadPos = new positionRecord();

        snakeHeadPos.Position = snakeHeadPosition;

        int foodIndex = allTheFood.IndexOf(snakeHeadPos);



        if (foodIndex != -1)
        {
            //Color foodColor;

            // foodColor = allTheFood[foodIndex].BreadcrumbBox.GetComponent<SpriteRenderer>().color;

            // sn.changeSnakeColor(sn.snakelength,foodColor);

            Destroy(allTheFood[foodIndex].BreadcrumbBox);

            allTheFood.RemoveAt(foodIndex);

            se.snakelength++;
        }
    }
Example #2
0
    /*
     * private void Update()
     * {
     *  if ((transform.position.x < -(Camera.main.orthographicSize - 1)) || (transform.position.x > (Camera.main.orthographicSize - 1)))
     *  {
     *      transform.position = new Vector3(-transform.position.x, transform.position.y);
     *  }
     *
     *  if ((transform.position.y < -(Camera.main.orthographicSize - 1)) || (transform.position.y > (Camera.main.orthographicSize - 1)))
     *  {
     *      transform.position = new Vector3(transform.position.x, -transform.position.y);
     *  }
     *
     *  myfoodgenerator.eatFood(this.transform.position);
     * }*/



    // Start is called before the first frame update
    void Start()
    {
        // enemyTail = Camera.main.GetComponent<SpawnEnemyAI>().snakelength;

        spawnEnemyAI = GetComponent <SpawnEnemyAI>();
        target       = GameObject.Find("blackPlayerBox").transform;


        //Debug.Log(this.name);

        //the instance of the seeker attached to this game object
        seeker = GetComponent <Seeker>();


        //node target by name
        //targetNode = GameObject.Find("TargetNode");

        //find the parent node of the point graph
        //graphParent = GameObject.Find("PointGraphObject");
        graphParent = GameObject.Find("AStarGrid");
        //we scan the graph to generate it in memory
        graphParent.GetComponent <AstarPath>().Scan();

        //generate the initial path
        pathToFollow = seeker.StartPath(transform.position, target.position);



        //update the graph as soon as you can.  Runs indefinitely
        StartCoroutine(updateGraph());

        //move the red robot towards the green enemy
        StartCoroutine(moveTowardsEnemy(this.transform));
    }