- Home /
Make a gameobject when you click
In my game, when I click in game, I want it to create a new game object in front of the player (similar to minecraft) please help I am a novice at unity
The way $$anonymous$$inecraft does it is specific to that game, as far as block generation is concerned you don't actually create something new, but rather change an existing mesh chunk. There are tons of tutorials for creating $$anonymous$$inecraft clones in Unity.
If you just want to create a GameObject, take a look at the User API with these terms:
Physics.Raycast
Camera.ScreenToWorldPoint
GameObject.Instantiate
Answer by SlowCircuit · Jun 10, 2018 at 12:25 AM
I'd highly suggested going through all the basic tutorials for Unity and if you don't know programming, then spend some time learning that too. When you run into an issue like this, it probably means you haven't done enough research. For this specific issue, you'd look up how to detect mouse input events, then look up how to instantiate objects.
Answer by SalahChafaiGameDesigner · Jun 10, 2018 at 12:32 AM
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Rotator : MonoBehaviour {
public Transform Player;
public GameObject Prefab;
void Start()
{
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
GameObject Clone;
Instantiate(Prefab, new Vector3(Player.position.x, Player.position.y, Player.position.z + 5.0f), Prefab.transform.rotation);
}
}
}
Your answer
Follow this Question
Related Questions
How to tell at runtime if a GameObject is a prefab 3 Answers
Distribute terrain in zones 3 Answers
Problem to play animation in C# 5 Answers
Multiple Cars not working 1 Answer