I’m in the need of assistance! The premise of my code is for me to have in-game cheats so that testing is easier and more fun. I’ll type out each game object and then put the code beneath it. My javascript is in its own folder and the c# script is under the standard assets folder. I know it’s really long, but hopefully you can understand whats going on
Player
script name- scriptDevControls
var motor : CharacterMotor;
var itty : boolean;
var viewIsScaleable : boolean;
var thighBurn : boolean;
var canPixelate : boolean = false;
var pixelEffect : boolean;
private var cheat_Enabled : boolean = false;
private var input : String = "";
private var cheatCorrect : boolean;
function Start ()
{
motor = GetComponent(CharacterMotor);
var pixelEffect : SimplePixelizer;
pixelEffect = GameObject.FindGameObjectWithTag("MainCamera").GetComponent("SimplePixelizer");
}
function Update ()
{
if (Input.GetKeyUp(KeyCode.BackQuote)||Input.GetKeyUp(KeyCode.C))
{
if (cheat_Enabled == true)
{
input = "";
cheat_Enabled = false;
Time.timeScale = 1.0;
}
if (cheat_Enabled == false)
{
cheat_Enabled = true;
Time.timeScale = 0.0;
}
}
if (canPixelate == true)
{
pixelEffect.enabled = true;
}
else
{
pixelEffect.enabled = false;
}
}
function OnGUI ()
{
if (cheat_Enabled == true)
{
Time.timeScale = 0.0;
input = GUI.TextField (Rect(0,0,200,30),input,300);
if (GUI.Button (Rect(200,0,170,30), "Activate Cheat") || Input.GetKeyDown (KeyCode.Return))
{
if (input == "scrollo")
{
viewIsScaleable = true;
}
if (input == "flash")
{
motor.movement.maxSidewaysSpeed = 10;
motor.movement.maxBackwardsSpeed = 10;
Time.timeScale = 1.0;
cheatCorrect = true;
}
if (input == "thigh burn")
{
motor.jumping.baseHeight = 2;
motor.jumping.extraHeight = 4;
Time.timeScale = 1.0;
cheatCorrect = true;
}
if (input == "itty")
{
transform.localScale = Vector3(0.1,0.1,0.1);
itty = true;
Time.timeScale = 1.0;
}
if (input == ("pixy"))
{
canPixelate = true;
}
if (input == "reset")
{
motor.movement.maxSidewaysSpeed = 5;
motor.movement.maxBackwardsSpeed = 5;
motor.jumping.baseHeight = 1.1;
motor.jumping.extraHeight = 1.1;
transform.localScale = Vector3(0.3,0.3,0.3);
viewIsScaleable = false;
canPixelate = false;
Time.timeScale = 1.0;
if (itty == true)
{
transform.position.y += 1;
itty = false;
}
cheatCorrect = true;
}
if (input != "reset"||"space"||"speedy")
{
cheatCorrect = false;
}
if (cheatCorrect == false)
{
Time.timeScale = 1.0;
}
cheat_Enabled = false;
}
GUI.Box(Rect(0,0,Screen.width,Screen.height),"");
}
}
Camera
script name- SimplePixelizer
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
[AddComponentMenu("Image Effects/SimplePixelizer")]
public class SimplePixelizer : MonoBehaviour {
public bool colorBlending = false;
public int pixelize = 8;
//Fixed Resolution
//Enabling fixed resolution will ignore the pixelize variable.
//It won't ignore colorBlending
public bool useFixedResolution = false;
public int fixedHeight = 640;
public int fixedWidth = 480;
//Check if image effects are supported
protected void Start() {
if (!SystemInfo.supportsImageEffects) {
enabled = false;
return;
}
}
//Downgrade the image
void OnRenderImage (RenderTexture source, RenderTexture destination) {
//Create the buffer
RenderTexture buffer = null;
//Set the resolution of the buffer
if(useFixedResolution) {
buffer = RenderTexture.GetTemporary(fixedWidth, fixedHeight, 0);
}
else {
buffer = RenderTexture.GetTemporary(source.width/pixelize, source.height/pixelize, 0);
}
//Change filter mode of buffer to create the pixel effect
buffer.filterMode = FilterMode.Point;
//Change filter mode of source to disable color blending/merging
if(!colorBlending) {
source.filterMode = FilterMode.Point;
}
//Copy source to buffer to create the final image
Graphics.Blit(source, buffer);
//Copy buffer to destination so it renders on screen
Graphics.Blit(buffer, destination);
//Release buffer
RenderTexture.ReleaseTemporary(buffer);
}
}