View DeActivatingGameObjects.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here is a bonus Unity example for 2D Game Design F21. Let me know what else you need! | |
====================================================================================== | |
(DE) ACTIVATING GAMEOBJECTS | |
Activate another GameObject on Start example: ShowOnStart.cs | |
Deactivate this GameObject on action (press space) example: HideOnAction.cs | |
Example Unity Project: https://drive.google.com/file/d/1qhtZZOpn83fH7DKXjtUJ8WmbGrK62By2/view?usp=sharing | |
Important: | |
1. ShowOnStart requires the GameObject you want to activate deactivated in your scene (uncheck the top-left box in its Inspector) |
View SwitchScene.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.SceneManagement; // Add Scene Management | |
public class SwitchScene : MonoBehaviour | |
{ | |
// Important: Don't forget to add the next scene to your project's Build Settings |
View JustOnce.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class JustOnce : MonoBehaviour | |
{ | |
// Has the thing already been done? | |
private bool alreadyDone = false; |
View KeyControl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class KeyControl : MonoBehaviour | |
{ | |
// Variables for keycodes that can be set in the Inspector | |
public KeyCode up = KeyCode.W; | |
public KeyCode down = KeyCode.S; | |
public KeyCode left = KeyCode.A; |
View Spin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Spin : MonoBehaviour | |
{ | |
// Set the velocity of rotation (positive numbers go counterclockwise, negative numbers go clockwise) | |
public float spinVelocity = 10f; | |
private Rigidbody2D rb2d; |
View FlapControl.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here is a bonus Unity example for 2D Game Design F21. Let me know what else you need! | |
====================================================================================== | |
A BASIC APPROACH TO FLAPPING | |
Full example: FlappyControl.cs | |
Important: | |
1. Flapping isn't exactly jumping. Our expectations of jumping in videogames tend to be much higher. This is dumb, bouncy, and messy (but fun!) | |
2. Your GameObject needs a Rigidbody2D component with Gravity Scale set to something other than 0. | |
3. The script interact's a lot with the Rigidbody2D properties Gravity Scale and Linear Drag. Experiment! |
View DestroyingThings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class DestroyingThings : MonoBehaviour | |
{ | |
// This example assumes you will use collision to destroy something. You can use the code inside of OnTriggerEnter2D as well | |
private void OnCollisionEnter2D(Collision2D collision) | |
{ | |
// If the other thing has a specific tag. It's a good idea to limit the detection to specific things |
View TriggerScene.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// Add SceneManagement to switch scenes | |
using UnityEngine.SceneManagement; | |
public class TriggerScene : MonoBehaviour | |
{ | |
// Create a string variable that you can set in the Inspector to specify the name of your new scene. You don't need quotes there. |
View Billboard.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code based on CameraFacingBillboard by Nei Carter: http://wiki.unity3d.com/index.php?title=CameraFacingBillboard | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Billboard : MonoBehaviour | |
{ | |
public Transform cameraTransform; | |
View QuitAndReset.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple quit and escape functionality | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// First, add this... | |
using UnityEngine.SceneManagement; | |
public class QuitAndReset : MonoBehaviour |
NewerOlder