Hi,
I want to make a basic game mechanic which is player teleports to a position of a dagger he throws. My problem is when i instantiate the dagger it doesn’t move and when i teleport it teleports to the initial position of the dagger.
My code as it follows;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UseDagger : MonoBehaviour
{
public GameObject daggerPrefabs;
public bool isDaggerEquipped;
Vector3 offset;
// Start is called before the first frame update
void Start()
{
isDaggerEquipped = true;
offset = new Vector3(0.4f, 0, 0.2f);
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Space) && isDaggerEquipped)
{
Instantiate(daggerPrefabs, transform.position + offset, Quaternion.identity);
daggerPrefabs.transform.Translate(Vector3.forward * Time.deltaTime, Space.Self);
isDaggerEquipped = false;
}
if(Input.GetKeyDown(KeyCode.Space) && !isDaggerEquipped)
{
transform.position = daggerPrefabs.transform.position;
isDaggerEquipped = true;
}
}
}
And also i want to destroy or remove the dagger player threw so there can’t be more than one dagger at the scene but Unity doesn’t allow me to destroy prefabs to avoid data loss by destroying asset as it says.
Could you please help me about that?