Instantiate along the Z/X Axis only?
My game is a 3D top down game, I currently have a setup where when you click some where on the screen and a sphere spawns where clicked but the problem is that it spawns along the Y and Z axis. but as my game is 3D top down i want it to only spawn where clicked along the Z axis so that it doesn't spawn floating at a random height in the air. This is the code im currently using to spawn the object when clicked using UnityEngine; using System.Collections; public class RaycastScript : MonoBehaviour { Ray myRay; // initializing the ray RaycastHit hit; // initializing the raycasthit public GameObject Planet; void Update() { myRay = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(myRay, out hit)) { if (Input.GetMouseButtonDown(0)) { Instantiate(Planet, hit.point + new Vector3(0, 0.5f, 0), Quaternion.identity); Debug.Log(hit.point); } } } }
Your answer
Follow this Question
Related Questions
Spawn Object on Set Score 0 Answers
Mixamo x Unity - Z axis animation 0 Answers
Problems with respawning using a very simple script 1 Answer
problem when i spawn to many Enemy the game be slower 1 Answer
Putting a cap on enemies spawned 2 Answers