Debugging Challenges
- Keshav Batra
- Oct 8, 2021
- 1 min read
These are actually my last debugging challenges for this week. The first one had me moving a cube and having it increase and decrease in size. The second one has me shooting balls on a single click of the left mouse button.
{
public float speed = 10f;
public float GrowScale = 2f;
public GameObject itemToSpawn;
// Update is called once per frame
void Update()
{
float xAxis = Input.GetAxis("Horizontal");
float zAxis = Input.GetAxis("Vertical");
transform.Translate(new Vector3(xAxis, 0f, zAxis) * speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.E))
{
transform.localScale = new Vector3(transform.localScale.x + GrowScale, transform.localScale.y + GrowScale, transform.localScale.z + GrowScale);
}
if (Input.GetKeyDown(KeyCode.Q))
{
transform.localScale = new Vector3(transform.localScale.x - GrowScale, transform.localScale.y - GrowScale, transform.localScale.z - GrowScale);
}
if (Input.GetMouseButtonDown(0))
{
Vector3 spawnLocation = new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z + 1f);
Instantiate(itemToSpawn, spawnLocation, Quaternion.identity);
}
}
Comments