hi can anyone help me. so im trying to teleport to the object i shoot but what happens is that i keep on teleporting to the same spot where i deleted the prefab object
public GameObject myPlayer;
public GameObject OrbPrefab;
public Rigidbody orb;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//teleport
Teleporting();
}
void Teleporting()
{
if(Input.GetKeyDown(KeyCode.E))
{
GameObject teleporter = (GameObject)Instantiate(OrbPrefab,Vector3.one,Quaternion.identity);
Vector3(transform.position.x,transform.position.y,transform.position.z);
transform.position = OrbPrefab.transform.position;
Destroy(teleporter);
}
}
her is the shoot
public Transform orb;
Transform orbshoot;
private Vector3 mouse_pos;
public Transform target;
private Vector3 object_pos;
private float angle;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
mouse_pos = Input.mousePosition;
mouse_pos.z = -10;
object_pos = Camera.main.WorldToScreenPoint(target.position);
mouse_pos.x = mouse_pos.x - object_pos.x;
mouse_pos.y = mouse_pos.y - object_pos.y;
angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, 0, angle);
if(orbshoot == null)
if(Input.GetMouseButtonDown(0))
{
orbshoot = Instantiate(orb) as Transform;
orbshoot.transform.position = transform.position + Camera.main.transform.right * 2;
Rigidbody rb = orbshoot.GetComponent<Rigidbody>();
rb.velocity = Camera.main.ScreenToWorldPoint(orb.position) * Time.deltaTime;
Destroy(orbshoot.gameObject,2.0f);
}
}
}
can anyone tell me why??