Skip to content

Instantly share code, notes, and snippets.

@brismithSFHS
Last active April 12, 2024 18:04
Show Gist options
  • Save brismithSFHS/9b5799107a0b9c144c36df52b6bbe6ac to your computer and use it in GitHub Desktop.
Save brismithSFHS/9b5799107a0b9c144c36df52b6bbe6ac to your computer and use it in GitHub Desktop.
A short script for making objects appear in Unity's Roll-a-Ball - works with the Input System
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Appear : MonoBehaviour
{
public GameObject ball;
public int count; // number of cubes needed to make this object appear
private PlayerController player;
private MeshRenderer mesh;
// Start sets up the components so that they recognize each other
// and turns off mesh renderer so that components aren't visible
void Start()
{
player = ball.GetComponent<PlayerController>();
mesh = this.GetComponent<MeshRenderer>();
mesh.enabled = false;
}
// Turns renderer on if # of cubes collected equals public count
void LateUpdate()
{
if (player.getCount() == count && !mesh.enabled)
{
mesh.enabled = true;
}
}
}
/* NOTE: Need to add this function to player controller script:
public int getCount()
{
return count;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment