If you see someone who needs to know about code tags, please link them to this post:
Please use code tags when posting code.
You can “tag” your code by typing around your code.
There is no overt “Code” tag button that automatically tags a selection as code.
That being said, however, we can Insert code directly into the post using the “Insert Code” button:
This will bring up an “Insert” window were we can paste our code and choose our language:
This will insert this code with Forum Markup that looks like this:
Note: that when manually inserting code, we can choose the language by using “=CSharp”
This is the final code in the post:
using UnityEngine;
using System.Collections;
public class Explode : MonoBehaviour {
public GameObject explosion;
public ParticleSystem[] effects;
void OnCollisionEnter2D (Collision2D collision) {
if (collision.gameObject.tag == "Hat") {
Instantiate (explosion, transform.position, transform.rotation);
foreach (var effect in effects) {
effect.transform.parent = null;
effect.Stop ();
Destroy (effect.gameObject, 1.0f);
}
Destroy (gameObject);
}
}
}
Note: the code is linked to the documentation with hyperlinks, so if you need to find out more about any piece of pasted code, follow these links to the documentation.
Hope this helps!
If you don’t use code tags, the code can be difficult to read:
using UnityEngine;
using System.Collections;
public class Explode : MonoBehaviour {
public GameObject explosion;
public ParticleSystem effects;
void OnCollisionEnter2D (Collision2D collision) {
if (collision.gameObject.tag == “Hat”) {
Instantiate (explosion, transform.position, transform.rotation);
foreach (var effect in effects) {
effect.transform.parent = null;
effect.Stop ();
Destroy (effect.gameObject, 1.0f);
}
Destroy (gameObject);
}
}
}