1

I got the code from a unity code pack and inside the utility pack are the scripts I am trying to reference. The thing is one of the references works but not all of it. Below is the code.

 private void HandleGridMovement()
{
    gridMoveTimer += Time.deltaTime;
    if (gridMoveTimer >= gridMoveTimerMax)
    {
        gridPosition += gridMoveDirection;
        gridMoveTimer -= gridMoveTimerMax;

        devourerMovePositionList.Insert(0, gridPosition);

        gridPosition += gridMoveDirection;
        
        if(devourerMovePositionList.Count >= devourerBodySize + 1)
        {
            devourerMovePositionList.RemoveAt(devourerMovePositionList.Count - 1);
        }

        for (int i=0; i < devourerMovePositionList.Count; i++)
        {
            Vector2Int devourerMovePosition = devourerMovePositionList[i];
            World_Sprite worldSprite = World_Sprite.Create(new Vector3(devourerMovePosition.x, devourerMovePosition.y), Vector3.one * .5f, Color.white);
            FunctionTimer.Create(worldSprite.DestroySelf, gridMoveTimerMax);

        }

        transform.position = new Vector3(gridPosition.x, gridPosition.y);
        transform.eulerAngles = new Vector3(0, 0, GetAngleFromVector(gridMoveDirection) - 90);

        levelGrid.DevourerMoved(gridPosition);
    }

So it's supposed to create a body part and then delete it shortly after, but in what I'm learning from, the guy's script works but mine doesn't because even though I reimported the utility script and rewrote my script for the character but this still marks the timer as nonexistent. Would I end up making my own timer?

3 Answers3

0

You should use this namespace: using System.Timers:

Please visit this page for more.

Orace
  • 7,822
  • 30
  • 45
Tidra
  • 95
  • 10
0

There is non FunctionTimer class in System or Unity namespaces.

Based on this question, you can try this:

Task.Delay(gridMoveTimerMax).ContinueWith(worldSprite.DestroySelf);

Or:

Task.Delay(TimeSpan.From$(gridMoveTimerMax)).ContinueWith(worldSprite.DestroySelf);

Where $ is whatever the unit of gridMoveTimerMax.

Orace
  • 7,822
  • 30
  • 45
0

Well I certainly feel like an idiot. I was scrolling up and noticed I hadn't even inserted the namespace referencing where the code from the other script was even coming from. I'm sorry for wasting everyone's time. Thanks in any case.