Fire script not working

using UnityEngine;
using System.Collections;

public class Fire : MonoBehaviour {

    public GameObject whiteCell;
    public string fireButton = "Fire1";
    public float shotPower = 1f;
    public int ammo = 20;

	// Use this for initialization
	void Start () {
        Instantiate (whiteCell, new Vector3(transform.position.x,-2.5f, 0), Quaternion.identity);
	// Update is called once per frame
	void Update () {
        //while (ammo > 0){
            //if (Input.GetButtonDown(fireButton)){
            //    Debug.Log("Hello");
        //        //ammo--;

        //whiteCell.transform.position += new Vector3(0, 0.1f, 0);
        whiteCell.rigidbody.AddForce(transform.up * shotPower);

I’m trying to shoot a “bullet” that will go directly upwards on the y-axis.
Unfortunately this is not working and I cannot get my head round why this is the case
I tried using the transform.position method and the rigidbody.AddForce method but both are not giving me results.

I’m sure there is something wrong with my code but I can’t find what exactly is wrong. Any insight will be greatly appreciated. Thanks :slight_smile:

‘transform.up’ is the ‘up’ of the object this script is attached to. Vector3.up is what you are looking for:

    whiteCell.rigidbody.AddForce(Vector3.up * shotPower);

Note if you are talking about going directly up the axis, then you need to Instantiate() or position the object on the axis (‘x’ and ‘z’ == 0), but you cannot do it at every update call. I’m not sure where you are going with this code, but try this:

if (Input.GetMouseButtonDown(0)) {
    whiteCell.transform.position =;
    whiteCell.rigidbody.AddForce(Vector3.up * shotPower);