Beginner Scripting (Scripts as Behaviour Components)

 For this weeks Extra credit task I decided to do one of the beginner scripting tasks. 

The one I chose was 'Scripts as Behaviour Components' mainly because it was the first one on the list. 

Ir ran through simple bits of programming such as changing the colour of the object such as pressing R for red, G for green etc.. 

Here is the example code used: 

using UnityEngine; using System.Collections; public class ExampleBehaviourScript : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.R)) { GetComponent<Renderer> ().material.color = Color.red; } if (Input.GetKeyDown(KeyCode.G)) { GetComponent<Renderer>().material.color = Color.green; } if (Input.GetKeyDown(KeyCode.B)) { GetComponent<Renderer>().material.color = Color.blue; } } }


This was only a quick 5min tutorial but was helpful either way. 

Comments

Popular Posts