Plz give me code for this program
How to print output of first n natural numbers in uI screen in unity 3
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Plz give me code for this program
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Feb 26, 2024, 6:58 AM EST
To achieve this in Unity using C#, you can create a simple script that populates a UI Text component with the first n natural numbers.
using UnityEngine; using UnityEngine.UI; public class NumberPrinter : MonoBehaviour { public Text numberText; void Start() { int n = 10; // Define the value of n string numbers = ""; for (int i = 1; i <= n; i++) { numbers += i + "\n"; } numberText.text = numbers; } }We create a
NumberPrinterclass that accesses a UI Text component to display the numbers. Adjust the valuento control the range of natural numbers displayed. This script can be attached to a GameObject in your Unity scene with a UI Text component to showcase the first n natural numbers.