- Home /
Auto Commenting lines
Hey guys! I made a static class (in C#) called CodeLine. What I want this class's functions to do is to be called from other scripts and be told to automatically comment out certain lines of code. For example, when you press down a button, the script will comment out a line of code for you. When you let go of the button, it will uncomment the line of code for you. Here's the script:
using System.Collections.Generic;
using System;
using UnityEngine;
public static class CodeLine {
public static void CommentLine(int line) {
}
public static void UncommentLine(int line) {
}
public static void CommentLine(int line, string word) {
}
public static void UncommentLine(int line, string word) {
}
}
Is it possible to put something in these functions that will comment and uncomment lines of code during gameplay? Thanks!
Answer by whydoidoit · Dec 08, 2012 at 05:46 PM
No you can't modify code like that during game play - it has already been compiled from the text. On certain platforms it might be possible to emit code at runtime, but I'm not sure that it's ever included. You certainly could never emit code on iOS or the web player.
You should probably consider using a Finite State Machine to control different parts of your game. I wrote a tutorial on Unity Gems about Finite State Machines that may help.