Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Philip Clevberger · Dec 04, 2010 at 01:22 PM · helloworld

Can I get an example of "Hello World" in Unity C#

Hi, I'm new to Unity 3D, My background is in Flash Actionscript3, so when I have been looking around for tutorials, it feels a bit like old skool flash where you attache snippets of code to visual objects on the screen. So my questions are.

  1. Is it possible to have something like a document class, a piece of code that runs first, where I can instantiate objects. Place things on screen etc. etc. As supposed to dragging and dropping things and placing things visually?

  2. C# seems neat so that's he most tempting way to go. I haven't been able to find any "getting started" tutorials. I would like something like HelloWorld, and maybe something where you get to set up the environment and throw a few cubes on the screen and get them to spin using code.

Thanks in advance /Philip

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sacredgeometry · Dec 04, 2010 at 11:48 PM 0
Share

you can use a null objet as that document class if you want, just run as script and stick the code you want to load on launch inside the awake or start methods. ie

void Start() { // code you want to launch here }

1 Reply

· Add your reply
  • Sort: 
avatar image
11

Answer by duck · Dec 04, 2010 at 01:41 PM

1) No, you have to have at least one script attached to a GameObject in your scene. This can be an empty gameobject (i.e. a non-visible item), but there's no scene root node, so you need this.

The script's "Awake" or "Start" functions can then be used to create and trigger other classes and functions. There's no "scene root node".

2) Here's a few of c# examples to make an object say hello, move, rotate, or be clickable in the scene:

// HelloWorld.cs (outputs a line of text to the console) using UnityEngine; public class HelloWorld : MonoBehaviour {

 void Start() {
     Debug.Log("Hello World!");
 }

}


// RotateMe.cs (rotates the object at a specified speed) using UnityEngine; public class RotateMe : MonoBehaviour {

 public float rotateSpeed = 10;
 void Update() {
     transform.Rotate( rotateSpeed * Time.deltaTime, 0, 0 );
 }

}


// MoveMe.cs (moves the object via the arrow keys) using UnityEngine;

public class MoveMe : MonoBehaviour {

 public float moveSpeed = 2;

 void Update() {
     float moveX = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
     float moveZ = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
     transform.Translate( moveX, 0, moveZ );
 }

}


// ClickHello.cs (outputs a line of text to the console when the object is clicked) using UnityEngine; public class ClickHello : MonoBehaviour {

 void OnMouseUp() {
     Debug.Log("Hello World! "+name+" was clicked!");
 }

}

These scripts show a few fundamental aspects of coding in Unity:

  • Public variables are exposed in the inspector
    This means you can adjust the variable's value for each object independently which uses this script, using Unity's inspector window

  • Framerate-indepenedent movement using Time.deltaTime This allows you to move an object at a constant speed regardless of the framerate currently being achieved by the computer. This avoids problems such as cars driving fater on higher-spec machines!

  • The Start and Update functions These are examples of built-in unity events which are sent by the engine. Start is called when an object comes into existence, and Update is called every frame. There are many other event functions which are sent to any scripts attached to Game Objects. For the full list, see the MonoBehaviour reference.

  • Direct references to common components, such as transform Because your script inherits from MonoBehaviour (by default), you inherit these properties which are useful aliases to common types of component that get attached to gameobjects such as "transform", "collider", "renderer" "light", "camera", etc. For the full list, see the Component reference.

  • Input class
    contains the API for all types of input including keypresses, buttons, custom axes, iphone touches, etc.

For more general information about getting started learning unity, see:

How can I start learning Unity fast?

Good luck!

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aalstes · Jul 23, 2013 at 03:17 PM 0
Share

This is just what I've been looking for! Thanks! :)

avatar image farmcp · Jul 13, 2014 at 11:44 PM 0
Share

Where would I be able to see the Debug.Log("hello world");?

avatar image Bunny83 · Jul 13, 2014 at 11:55 PM 0
Share

@farmcp:
In the Console window

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

need teleport script fixed slightly 1 Answer

Swapping out parts of a model in code 3 Answers

help with movement along x axis and slow down. please help 1 Answer

C# Script Template - how to make custom changes? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges