- 追加された行はこの色です。
- 削除された行はこの色です。
#contents
*はじめに [#x7454d9b]
&size(18){[[Unity 初学者のすゝめ]]};の続きです。
#br
「[[Unity 初学者のすゝめ]]」では重力操作や当たり判定などの簡単な物理演算による操作を勉強しました。
しかし、さらに複雑な操作をしようと思うとプログラミングでの操作が必要になります。
そのため、このページではUnity上でのC#のプログラミングの基本を勉強します。
#br
*ひつじをC#で動かしてみる [#a2e972d3]
「[[Unity 初学者のすゝめ]]」
すると、プロジェクトのアセットに「text.cs」というのが追加されました。
これをダブルクリックします。
#br
#geshi(csharp,number){{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
}}
#br
#geshi(csharp,number){{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Vector3 pos = this.transform.position;
pos.x = 3;
pos.y = 4;
this.transform.position = pos;
}
// Update is called once per frame
void Update()
{
}
}
}}
#geshi(csharp,number){{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 pos = this.transform.position;
pos.x += 0.01f;
pos.y += 0.01f;
this.transform.position = pos;
}
}
}}
#geshi(csharp,number){{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
public float speed = 0.01f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 pos = this.transform.position;
pos.x += speed;
pos.y += speed;
this.transform.position = pos;
}
}
}}
#geshi(csharp,number){{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
public float speed = 0.01f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (this.transform.position.x > 5 || this.transform.position.x < -5)
{
speed = -speed;
}
Vector3 position = this.transform.position;
position.x += speed;
position.y += speed;
this.transform.position = position;
}
}
}}
#geshi(csharp,number){{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
public float speed = 0.01f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (this.transform.position.x > 5 || this.transform.position.x < -5)
{
speed = -speed;
}
Vector3 position = this.transform.position;
position.x += speed;
position.y += speed;
this.transform.position = position;
}
}
}}