BerkinAkkaya

Object Placing System

Oct 2nd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class PlacingObjects : MonoBehaviour {
  4.  
  5.     [SerializeField] GameObject obj;
  6.  
  7.     void Update(){
  8.         if(Input.GetMouseButtonDown(0))
  9.             CreateObject(MousePosition);
  10.     }
  11.  
  12.     void CreateObject(Vector3 position){
  13.         Instantiate(obj, position, Quaternion.identity, transform);
  14.     }
  15.  
  16.     Vector2 MousePosition{
  17.         get{
  18.             Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  19.             return worldPoint;
  20.         }
  21.     }
  22.  
  23.     /* berkinakkaya.wixsite.com/blog */
  24. }
Advertisement
Add Comment
Please, Sign In to add comment