K
K
KotMilkMeoW2021-12-08 18:36:58
C++ / C#
KotMilkMeoW, 2021-12-08 18:36:58

How to make increment variable while true in unity c#?

I want to make the variable increment constantly (or once per second)
I wrote the following code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Timers;
using System;

public class SilSec : MonoBehaviour
{
    void Update()
    {
        Silicon sil = new Silicon();
        while (true)
        {
            sil.silicon++;
            print("meow");
        }
        
    }

    
}

Nothing happens.
variable silicon there:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Silicon : MonoBehaviour
{
    public int silicon = 0;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Griboks, 2021-12-08
@KotMilkMeoW

Silicon sil = new Silicon();
void Update()
    {
        sil.silicon++;        
    }

Update is the built-in while.

F
freeExec, 2021-12-08
@freeExec

while (true) {}- and when should the yutin work if you locked it in the cycle?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question