- Home /
Drop item into a certain/fixed position
What i wanted to do is to drop an object into a certain/fixed position. Can anyone help me with my problem,What would I do to solve my problem?.
Thanks in Advance guys.
Have you had a go at it and done a bit of googling? Or written some code?
Answer by logicandchaos · Aug 26, 2020 at 12:31 AM
you set the objects transform.position
By the way do you know if you can help me with my problem. I want to find the last item that used a specific code then instantiate it, This is a drop item system for my stickman game. So Heres the Code: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement; using UnityEngine.UI;
public class Itempickup : $$anonymous$$onoBehaviour { public GameObject Item; bool playerContact; public Transform Feet; public bool equippedOn; public GameObject ThisItem; public Layer$$anonymous$$ask Weapons; public GameObject LastItem; public GameObject This; public GameObject It; [SerializeField] private Text text;
public void Start()
{
text.gameObject.SetActive(false);
}
private void OnTriggerEnter2D(Collider2D collision){
if(collision.CompareTag("Pickup")){
playerContact = true;
text.gameObject.SetActive(true);
}
}
void OnTriggerExit2D(Collider2D collision)
{ if (collision.CompareTag("Pickup")) playerContact = false; text.gameObject.SetActive(false);
}
private void Update(){ if (playerContact == true && Input.GetKeyDown(KeyCode.E)) {
GameObject[] ThisItem = GameObject.FindGameObjectsWithTag ("Weapons");
foreach(GameObject go in ThisItem)
{
go.SetActive(false);
Spawn();
}
Equip();
}
if(Input.GetKeyDown(KeyCode.G))
{
ThisItem.SetActive(true);
Item.SetActive(false);
}
}
void Equip()
{
Item.SetActive(true);
//ThisItem.SetActive(false);
Destroy(gameObject);
equippedOn = true;
}
void Spawn() {
Instantiate(ThisItem, transform.position, Quaternion.identity);
Debug.Log("Prefab $$anonymous$$ade" + ThisItem.name);
}
void Drop() { It.SetActive(false); This.SetActive(true); equippedOn = false;
} }
By the way im a beginner coder so there is probably a faster way
Answer by Llama_w_2Ls · Aug 27, 2020 at 03:52 PM
You can attach an event system component onto the object you want to drag and run public functions whilst being dragged and whilst being dropped. You can set the objects transform.position to the Input.mousePosition;
Your answer
Follow this Question
Related Questions
Picking up a box 2 Answers
Drag Drop Inventory With GUI Buttons. 0 Answers
Networking 5.1 drops framerate 0 Answers
Item pickup and drop function 2 Answers