Search Unity

Not shooting at all

Discussion in 'Scripting' started by qiqette, Feb 13, 2016.

  1. qiqette

    qiqette

    Joined:
    Feb 7, 2016
    Posts:
    121
    Why it isn't shooting?
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Shot : MonoBehaviour{
    5.  
    6.     public Rigidbody bullet;
    7.     public float speed = 20;
    8.  
    9.     public void onclickshot(){
    10.             Rigidbody clone = Instantiate(bullet,transform.position,transform.rotation)as Rigidbody;
    11.             clone.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
    12.  
    13.     }
    14. }
    I have one empty object with the script and the rigidbody asigned and a button with this emptyGameObject and the scripting onclickshot()
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    why are you converting it to rigidbody? just simply use it as a GameObject and then clone.GetComponent<Rigidbody>.velocity
     
  3. qiqette

    qiqette

    Joined:
    Feb 7, 2016
    Posts:
    121
    Yeah, i did it, but still not working...
     
  4. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Try instead of the TransformDirectionStuff:
    clone.velocity = speed * transform.fwd;