概要
unity5.2の作法、調べてみた。
マウスで線をひく、やってみた。
makefile
- menu->file->new sceneする。
- menu->file->save sceneでsenとする。
- menu->gameobject->create emptyする。
- menu->assetes->creates->c# scriptでsen.csつくる。
- ダブルクリックして、コードを書く。
- ヒエラルキーのgameobjectに、コードを重ねる。
- 三角で実行。
サンプルコード
using UnityEngine;
using System.Collections;
public class sen : MonoBehaviour {
LineRenderer lr;
int n;
void Start () {
lr = new GameObject().AddComponent<LineRenderer>();
lr.SetColors(Color.red, Color.red);
lr.useWorldSpace = true;
lr.SetWidth(0.5f, 0.5f);
n = 0;
}
void Update () {
if (Input.GetMouseButtonDown(0))
{
lr.SetVertexCount(n + 1);
Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
lr.SetPosition(n, new Vector3(point.x, point.y, 0f));
n++;
Debug.Log(n);
}
if (Input.GetMouseButtonUp(1))
{
lr.SetVertexCount(0);
n = 0;
}
}
}
以上。