instantiated game object
の位置を変更したいと思います。そのために私はUI button
を使用しました。ユーザーがボタンをクリックすると、キューブはinstantiated
になり、ユーザーがそのインスタンス化されたキューブをクリックしてUI slider
を移動すると、そのキューブの位置がスライダの値に従って変更されます。インスタンス化されたゲームオブジェクトを移動する
私はこの方法を試してみましたが、それは動作しません。ここで間違っているのは何ですか?
using UnityEngine;
using System.Collections;
public class instantiate : MonoBehaviour
{
public GameObject cube;
public float speed = 0f;
public float pos = 0f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
Debug.Log("Clicked");
if (hit.collider.tag == "Cube")
{
// Destroy(hit.collider.gameObject);
// Destroy(this);
speed += Input.GetAxis("Horizontal");
hit.collider.gameObject.transform.eulerAngles = new Vector3(0, 0, speed);
hit.collider.gameObject.transform.position = new Vector3(0, 0, pos);//pos
}
}
}
}
public void objinst()
{
Instantiate(cube, new Vector3(0, 0, 0), Quaternion.identity);
}
public void rotatess(float newspeed)
{
speed = newspeed;
}
public void positions(float newpos)
{
pos = newpos;
}
}
オブジェクトをスライドさせるときにどの軸を移動しますか? – Programmer
@プログラマーZ軸 – user3789211