EDIT: The issue is solved, I found a ; on line 29 after if (other.tag == “Boost”)
After removing this it works great
Hey, first of all thanks for a great course.
I’ve just finalized lesson 27 (Boosts & Bumps) and just saw that it doesn’t matter if I trigger the boost, package or customer, it will always set moveSpeed = boostSpeed; for some reason
I’ve looked through the code on gitlab but can’t see that I have done something wrong.
I have set my speed up to have the tag “Boost” and my pizza/packages to have the tag “Pizza” to separate them even further.
These are my changes compared to Ricks code (from what I can see)
- hasPackage = pizzaBoxes
- tag = Pizza
- I added else if for if I don’t have a Pizza
- The debug text
Anyone got some ideas what might be wrong?
Driver.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Driver : MonoBehaviour
{
[SerializeField] float steerSpeed = 1f;
[SerializeField] float moveSpeed = 20f;
[SerializeField] float slowSpeed = 15f;
[SerializeField] float boostSpeed = 30f;
void Update()
{
float steerAmount = Input.GetAxis("Horizontal") * steerSpeed * Time.deltaTime;
float moveAmount = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
transform.Rotate(0, 0, -steerAmount);
transform.Translate(0, moveAmount, 0);
}
void OnCollisionEnter2D(Collision2D other)
{
moveSpeed = slowSpeed;
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Boost");
{
moveSpeed = boostSpeed;
}
}
}
Delivery.cs
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Delivery : MonoBehaviour
{
[SerializeField] bool pizzaBoxes;
[SerializeField] float destroyDelay = 0.5f;
[SerializeField] Color32 hasPizzaColor = new Color32 (1, 1, 1, 1);
[SerializeField] Color32 noPizzaColor = new Color32(1, 1, 1, 1);
SpriteRenderer spriteRenderer;
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
}
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("Bump!");
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Pizza" && !pizzaBoxes)
{
Debug.Log("You picked up the Pizza!");
pizzaBoxes = true;
spriteRenderer.color = hasPizzaColor;
Destroy(other.gameObject, destroyDelay);
}
else if (other.tag == "Pizza" && pizzaBoxes)
{
Debug.Log("You already have a Pizza for delivery");
}
if (other.tag == "Customer" && !pizzaBoxes)
{
Debug.Log("You have no Pizza to deliver");
}
else if (other.tag == "Customer" && pizzaBoxes)
{
Debug.Log("You delivered the Pizza!");
pizzaBoxes = false;
spriteRenderer.color = noPizzaColor;
Destroy(other.gameObject, destroyDelay);
}
}
}