- Home /
Question by
TotalFreeze · May 15, 2013 at 10:42 AM ·
range
Shotgun range?
Hello, I'm trying to make my cube to shoot a shotgun. The problem is that I want the shotgun to have a maximum range where everything(zombies, soldiers) that is before the maximum range to explode. My problem is that my cube is moving on the x and y axis. So I wouldn't know how to set the limit on my x and y axis. Also destroy the object once it goes further than its minumum range. Its a 2d game being made in c#
private Transform myTransform; public float shootingSpeed = 5f; public float specialgunSpeed = 10f;
// Use this for initialization
void Start () {
myTransform = transform;
}
// Update is called once per frame
void Update () {
float amntSpeed = shootingSpeed * Time.deltaTime;
myTransform.Translate(Vector3.up * amntSpeed);
myTransform.Translate(Vector3.forward * amntSpeed);
if(myTransform.position.y >= 8f){
Destroy(this.gameObject);
}
}
//Special guns are shotguns, rpgs, etc
void SpecialGuns(){
float amntSpeed = specialgunSpeed * Time.deltaTime;
//This is the guy I worry about.
myTransform.Translate(Vector3.Max (3f,3f) *amntSpeed);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613102248im_/https://answers.unity.com/themes/thub/images/avi.jpg)