- Home /
 
 
               Question by 
               Ballistic_GMD · Oct 26, 2018 at 10:57 PM · 
                c#2d gametouches  
              
 
              Please how do i make this code to fire missile at different touch positions on screen simultaneously.
 /*the one below works for firing one missile and then another after the first has been destroyed,
 if  i fire more than one missile intantaneously at different positions ,they both move to the last position i touched.*/
 //code attached to game manager to fire missile
  void Update() 
     {
        touchposition = new Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y);
    if (Input.GetTouch(0).phase == TouchPhase.Began && ( MissileAmount>0))
          {
              targetpos = (Vector2)Camera.main.ScreenToWorldPoint(touchposition);             
              Instantiate(missile, new Vector2(-0.42f, -6f), missile.rotation);
              MissileAmount--;
        }
 }
 //code attached to missile game object to move to target position.
 public class Antimissile : MonoBehaviour {
     public Rigidbody2D ms;
     private float speed= 8f;
     private float rotateSpeed = 800f;
     void Start ()
     {
       GM.ftarget = GM.targetpos;
     }
    void Update()
     {  
             float step = speed * Time.deltaTime;
             Vector2 direction = (Vector2)GM.ftarget - ms.position;
             direction.Normalize();
             float rotateAmount = Vector3.Cross(direction, transform.up).z;
             ms.angularVelocity = rotateAmount * rotateSpeed;
             transform.position = Vector2.MoveTowards(transform.position, GM.ftarget, step);   
     }
 
 
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Best way to move a 2D Character 2 Answers
How to make a tick speed for heart health system?,How to make a tick speed for health script? 1 Answer
How to Find gameObject child. 3 Answers