This question was
closed Sep 05, 2015 at 10:15 PM by
_Sewq90 for the following reason:
The question is answered, right answer was accepted
Finding Vector3 position of GameObject
Hello, I need help with spawning a cube at the "gun" object, I got it working with fixed coordinates but do nowt know how to do it with something that moves, this is the error I get now:
Cannot implicitly convert type UnityEngine.GameObject' to
UnityEngine.Vector3'
using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class Shoot : MonoBehaviour {
public int m_Ammo;
private Vector3 gun = GameObject.Find("Gun");
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (CrossPlatformInputManager.GetButtonDown("Fire1") && m_Ammo >= 1)
{
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.AddComponent<Rigidbody>();
cube.transform.position = new Vector3(gun);
}
}
Comment
Best Answer
Answer by getyour411 · Sep 05, 2015 at 10:06 PM
gameObject.transform.position is the Vector3 "gun" object location you are looking for