Closed head-iie-vnr closed 4 months ago
Steps followed
Added below script
I am able to move the ball.
Created gold coins. Added rotate function to them so that they move vertically.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotate : MonoBehaviour
{
public Vector3 rotateAmount = new Vector3( 0 , 0 , 1);
public int speed = 4;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Rotate(rotateAmount * speed);
}
}
Now the simulation looks like below
Change camera angle to make the board look more appealing
In the Unity Editor, go to the top menu and select GameObject > UI > Text. This will create a new Text element in the scene. You should see a new Canvas object and a Text object as a child of the Canvas in the Hierarchy window.
Select the newly created Text object in the Hierarchy. In the Inspector window, rename the Text object to ScoreText.
Position the Text Element:
With the Text object selected, you can adjust its position using the Rect Transform component in the Inspector. You can also adjust the size, font, color, and other properties to make the score display as you like.
Fit it so that it looks like below
In the Hierarchy window, right-click and select Create Empty. This will create a new empty GameObject. Rename this GameObject to ScoreManager.
Create the ScorerManager.cs script in the Assets > scripts.
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ScoreManager : MonoBehaviour
{
public static ScoreManager instance;
public TextMeshProUGUI scoreText;
private int score = 0;
void Awake()
{
Debug.Log("Called Score Manager");
if (instance == null)
{
instance = this;
Debug.Log("new instane is created");
}
else
{
Destroy(gameObject);
}
}
void Start()
{
UpdateScoreText();
}
public void AddScore(int amount)
{
score += amount;
UpdateScoreText();
}
void UpdateScoreText()
{
scoreText.text = "Score: " + score;
}
}
With the ScoreManager GameObject selected, go to the Inspector window. Click on Add Component and search for the ScoreManager script to attach it.
In the Hierarchy window, select the ScoreManager GameObject. In the Inspector window, you should see the ScoreManager script component. There should be a field named ScoreText. Click the small circle next to this field to open the object picker. Select the ScoreText object from the list.
Got error: Assets/scripts/ScoreManager.cs(7,12): error CS0246: The type or namespace name 'TextMeshProUGUI' could not be found (are you missing a using directive or an assembly reference?)
Imported
Quick check on Windows > Package Manager reveals that it was not there.
I tried installing using URL
Now you should be able to attach the variable to the
Ensure that Ball has 'Sphere Collider
' enabled. But Is Trigger
disabled.
Select all coins and check in the inspector that it has 'Cylendar Collider'.
Enable the Is Tigger
attribute.
A Rigidbody is usually added to the ball to enable physics-based movement and interactions.
A Collider is used to define the physical boundaries of an object for collision detection. Colliders can be of various shapes, such as boxes, spheres, capsules, meshes, etc.
When the Is Trigger property of a collider is enabled, it changes how the collider interacts with other colliders:
The collider acts as a solid object. Physical interactions like collisions will occur. For example, a ball will bounce off a wall. Collision events like OnCollisionEnter, OnCollisionStay, and OnCollisionExit are used. Is Trigger Enabled (checked):
Objects can pass through the trigger collider without physical collision. Trigger events like OnTriggerEnter, OnTriggerStay, and OnTriggerExit are used to detect when other colliders enter, stay within, or exit the trigger area.
In Unity, the Rigidbody
component is used to make an object respond to physics. The Rigidbody component includes several properties that control how physics is applied to the object. Here’s an explanation of some key properties:
These properties help control the physics behavior of objects in your Unity scene, allowing for realistic movements and interactions.
Now the board looks like below
Known issues to be fixed later
Next Features
Work scope