Ways to Unity 2: first line of code with csharp
create a Scripts
folder
This folder should be at the same level of Scenes
create a c# script
The name of that file is PlayerController
And it has the following contents:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
install vscode, .net SDK, mono
Just do a google, guys.
- https://code.visualstudio.com/download
- https://snapcraft.io/dotnet-sdk
- https://www.mono-project.com/download/stable/
- https://github.com/OmniSharp/omnisharp-vscode/issues/3351
- https://code.visualstudio.com/docs/other/unity
*.csproj
and *.sln
is required if you want to have a full experience of code auto-completion.
attach your script to your object
Because you want to use your script to control your object.
Here is how you do it: drag that script directly to the object that shows inside of the Hierarchy
window.
move your object with one line of code
void Update()
{
transform.Translate(0,0,1);
//transform.Translate(Vector3.forward);
//transform.Translate(Vector3.forward * Time.deltaTime * 20);
}
add collision effects or physical rules to your object
Just add a component called Rigidbody
to your object. It’s done.
And also, there has a parameter about the Rigidbody
, the mass
. 1 mass
== 1 kilogram
.
how to duplicate your object
Just select the object that you want to duplicate, then press ctrl+d
, it’s done. All you have to do next is to drag the new object out from the old one.
origin link
https://yingshaoxo.blogspot.com/2020/11/ways-to-unity-2-first-line-of-code-with.html