Learn about programming from scratch, then progress to create detailed code for your projects.
Beginner Gameplay Scripting
Scripts as Behaviour Components
What are Scripts in Unity? Learn about the behaviour component that is a Unity script, and how to Create and Attach them to objects
C#:
using UnityEngine;
using System.Collections;
public class ExampleBehaviourScript : MonoBehaviour
{
void Update ()
{
if(Input.GetKeyDown(KeyCode.R))
{
gameObject.renderer.material.color = Color.red;
}
if(Input.GetKeyDown(KeyCode.G))
{
gameObject.renderer.material.color = Color.green;
}
if(Input.GetKeyDown(KeyCode.B))
{
gameObject.renderer.material.color = Color.blue;
}
}
}
JS:
#pragma strict
function Update ()
{
if(Input.GetKeyDown(KeyCode.R))
{
gameObject.renderer.material.color = Color.red;
}
if(Input.GetKeyDown(KeyCode.G))
{
gameObject.renderer.material.color = Color.green;
}
if(Input.GetKeyDown(KeyCode.B))
{
gameObject.renderer.material.color = Color.blue;
}
}
BOO:
import UnityEngine
import System.Collections
public class ExampleBehaviourScript(MonoBehaviour):
private def Update():
if Input.GetKeyDown(KeyCode.R):
gameObject.renderer.material.color = Color.red
if Input.GetKeyDown(KeyCode.G):
gameObject.renderer.material.color = Color.green
if Input.GetKeyDown(KeyCode.B):
gameObject.renderer.material.color = Color.blue
0 comments:
Post a Comment