I saw someone else had a similar issue, where packages and customers also boosted instead of acting as customers or packages. Unfortunately, their solution is not applicable to my situation. Customers are still tagged as customers, Packages are still tagged as packages, Boosts are still tagged as boosts. I did nothing to edit the delivery script, and built the driver script as prescribed in the coursework. Here’s my codes, if anyone may be able to help.
Delivery:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Delivery : MonoBehaviour
{
[SerializeField] Color32 hasPackageColor = new Color32 (1, 1, 1, 1);
[SerializeField] Color32 noPackageColor = new Color32 (1, 1, 1, 1);
[SerializeField] float destroyDelay = 0.5f;
bool hasPackage;
SpriteRenderer spriteRenderer;
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
}
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("JESUS Ricky! You been drinkin?!");
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Package" && !hasPackage)
{
Debug.Log("Hope that wasn't fragile...");
hasPackage = true;
Destroy(other.gameObject, destroyDelay);
spriteRenderer.color = hasPackageColor;
}
if (other.tag == "Customer" && hasPackage)
{
Debug.Log("Here's yah friggin box of crap!");
hasPackage = false;
Destroy(other.gameObject, destroyDelay);
spriteRenderer.color = noPackageColor;
}
}
}
Driver:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Driver : MonoBehaviour
{
[SerializeField] float steerSpeed = 200;
[SerializeField] float moveSpeed = 15;
[SerializeField] float slowSpeed = 1;
[SerializeField] float boostSpeed = 30f;
// Update is called once per frame
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")
Debug.Log("Holy #@$% wuwuzzat?!");
moveSpeed = boostSpeed;
}
}