I would like to substitute a number for each score
Prepare the ball and Cube objects
When the ball hits the Cube, the number of the ball is taken and reflected in the score.
The first score display was fine, but I didn't know after the second one, so it stopped
Learn more
·We have prepared 43 balls so that you can get numbers by the object name (number) of the ball.
·If one of 43 hits the Cube, it will be displayed in the first score (where Scene 1 in the image) and the lottery for Scene 1 will end
·If you press the button to go to the next Scene, it becomes Scene 2 and the second lottery starts
オブジェクト To prevent object destruction, we are making it possible to take over using DontDestroyOnLoad
·The score has also been taken over, so if you draw for the second time at this stage, it will be reflected in the first time.
·The script below will only reflect the text you specified, so only Scene1 will be reflected
*We are reducing the number currently available
There is no script on the ball
Source Code
For Cube
using System.Collections;
using System.Collections.General;
using UnityEngine;
using UnityEngine.UI;
using System.Text.RegularExpressions;
public class defense —MonoBehavior
{
public Text number;
// Make a one-time decision in the event of a collision
void OnCollisionEnter (Collision)
{
for (inti=1; i<=5;i++)
{
if(collision.gameObject.name=="Item("+i.ToString()+")")")
{
number.text=i.ToString();
Debug.Log (collision.gameObject.name);
}
}
}
}
Script I put in the button
using UnityEngine.SceneManagement;//Enable Scene Management
public class GameController 2: MonoBehavior
{
public void to GameScene()
{
SceneManager.LoadScene("Scene2");
}
}
Tried
Add the above script
How to duplicate UI Text in Unity 4.6
I was able to clone and increase the text on this site
br/>
After all, I failed when I put it in my score.
US>Version
unity2019
The actual Text object referenced by the public Text number in Defense is
Text object (leftmost) that Scene1 wants to reflect,
For Scene 2, is it the Text object (second from left) that you want to reflect for Scene 2?
Open the GameObject inspector to which you attached the Defense and check the Text object assigned to number.
Also, let's look at the log of the number variable
Debug.Log (number.gameObject.Name);
© 2024 OneMinuteCode. All rights reserved.