Search Unity

Infinite runner and shooter

Discussion in '2D' started by unity_9362314, Oct 19, 2018.

  1. unity_9362314

    unity_9362314

    Joined:
    Oct 11, 2018
    Posts:
    6
    Hello Friends,

    I was wondering if someone could help me with a script of a character that when is spawn starts moving and shooting inifintly and instanlty without any key inputs...

    I would really appreciate your effort.

    Thank you.
     
  2. barskey

    barskey

    Joined:
    Nov 19, 2017
    Posts:
    207
    Code (CSharp):
    1. public Vector2 mySpeed;
    2.  
    3. private RigidBody2D rb;
    4. private bool alive;
    5.  
    6. void Awake ()
    7. {
    8.   rb = gameObject.AddComponent<RigidBody2D> () as RidigBody2D;
    9.   rb.bodyType = RigidBodyType2D.Kinematic;
    10. }
    11.  
    12. void Start ()
    13. {
    14.   alive = true;
    15.   rb.velocity = mySpeed;
    16.   ShootInfinitely ();
    17. }
    18.  
    19. IEnumerator ShootInfinitely ()
    20. {
    21.   while (alive)
    22.   {
    23.     // put your shooting code in here
    24.   }
    25. }
    26.  
    27. void OnDestroy ()
    28. {
    29.   alive = false;
    30. }
     
  3. unity_9362314

    unity_9362314

    Joined:
    Oct 11, 2018
    Posts:
    6
    i Love you so much! Thank you Barskey