Question by
Gymsock · Oct 27, 2018 at 04:06 PM ·
transformtrigger2d-platformergameobjects
Resetting my cannon fire to its original transform
Hi all I am very new to unity and coding so hopefully I can make this question clear enough to answer but I'm trying to program my bullet to re spawn to is original transform as soon as its hits a trigger however I'm not quite sure what to code to make that happen. Here is my script thus far...
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class Bullet : MonoBehaviour { public GameObject targetObjectdeath; public GameObject targetObjectrespawn; private object originalPosition; public float moveSpeed;
private Rigidbody RB;
private void OnTriggerEnter(Collider other)
{
if (targetObjectdeath == null)
return;
if (other.tag != "Player")
return;
targetObjectdeath.SetActive(false);
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
{
if (targetObjectrespawn == null)
return;
if (other.tag != "Exit")
return;
targetObjectrespawn.SetActive(false);
}
}
// Use this for initialization
void Start ()
{
RB = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update ()
{
RB.velocity = new Vector3(-moveSpeed, RB.velocity.y); //line of script from YouTube tutorial https://www.youtube.com/watch?v=GrQalFLtQT4
}
}
If anyone could help me out it would be much appreciated.
Many thanks!
Comment