Hi,
I’m making a gun system, and when I click I instantiate a bullet with the player position, the problem is that:
//BulletScript attached to the bullet Gameobject
using UnityEngine;
using System.Collections;
public class BulletScript : MonoBehaviour {
// Use this for initialization
void Start () {
float x = GameObject.Find("Player").transform.FindChild("mainCam").transform.position.x+3;
float y = GameObject.Find("Player").transform.FindChild("mainCam").transform.position.y;
float z = GameObject.Find("Player").transform.FindChild("mainCam").transform.position.z+3;
transform.position = new Vector3(x, y, z);
}
// Update is called once per frame
void Update () {
transform.rigidbody.AddForce(transform.eulerAngles*10);
}
}
And the second script:
//GunScript attached to the Inventory Item (it's a MP5)
using UnityEngine;
using System.Collections;
public class GunScript : MonoBehaviour {
GameObject bullet;
// Use this for initialization
void Start () {
if(Input.GetMouseButtonDown(0)) { //This is weird because I have to use it in the Start void, and not in the Update
bullet = GameObject.Instantiate(Resources.Load("Models/Items/Bullets/bala"), GameObject.Find("Player").transform.FindChild("mainCam").transform.position, GameObject.Find("Player").transform.FindChild("mainCam").transform.rotation) as GameObject;
}
}
// Update is called once per frame
void Update () {
}
}
How can I solve that?
Thanks in advance.
Bye.