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