Adding a position to an enemy class?

I’m trying to get a position variable for an object in lets say…an enemy class;
how can i use the transform component to get the x,y,z position of the enemy object?

Public Class Enemy{
Public GameObject eObject;
Public float enemyXpos;
Public float enemyYpos;
public float enemyZpos;
public int health;

Public Enemy(x,y,z,hp)
{
enemyXpos = x;   ???? 
enemyYpos = y;  ????
enmeyZpos = z;   ????
health = hp
}

}
   Public Class Manager{
             Enemy enemy = new Enemy(<enemyXpos> ,<enemyYpos> ,<enemyZpos>,<health> );

             void Start(){

             }
             void Awake(){

             }

    }

Am I on the right track :/??

using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour {
	
	public int Health;
	public GameObject eObject;
	public Transform ePosX = eObject.transform.position.x; ??? 
	public Transform ePosY = eObject.transform.position.y; ???
	public Transform ePosZ = eObject.transform.position.z; ???
	

	Transform transform;
	
	void Awake()
	{
		transform = GetComponent<Transform>();	
	}
	
	public Enemy( ?var x, ?var y , ?var z  int hp)
	{
                ePosX = x;
                ePosY = y;
                ePosZ = z;
		Health = hp;		
	}
	
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

No, you cant set fields like that, your syntax is all wrong, and i am not sure on exactly what you are trying to do.

With the limited information you gave, why can you not simply do this?

public class Enemy : MonoBehaviour {

    

    public int Health;

    public GameObject eObject;

    private float xPos, yPos, Zpos;

    

    void Start()

    {
        xPos = eObject.transform.position.x;
        yPos = eObject.transform.position.y;
        Zpos = eObject.transform.position.z;
    }


}

Assuming you want to get the positions of the eObject GameObject.

Maybe this is what you are trying to achieve, but i am just guessing

public class Enemy
{
    public GameObject eObject;

    public float enemyXpos;

    public float enemyYpos;

public float enemyZpos;

public int health;

    public Enemy(GameObject go, Transform pos, int hp)
    {
        eObject = go;
        enemyXpos = pos.position.x;
        enemyYpos = pos.position.y;
        enemyZpos = pos.position.z;
        health = hp;
    }
}

public class Manager : MonoBehaviour
{
    private Enemy enemy;
    public GameObject enemyGO;
    public int health = 100;

    void Start()
    {
        enemy = new Enemy(enemyGO, enemyGO.transform, health);
    }
}

Im trying to get it so when i call an enemy from the enemy class i can set its vector 3 position in the world.

Like

Enemy enemy = new Enemy(X,Y,Z)

draw at XYZ

:stuck_out_tongue: idk lol

I just updated my previous post, but like i said, i don’t fully understand what you are after.

I would suggest looking at the Unity documentation for prefabs and game objects.

Do you mean something like that:

transform.position = new Vector3 (xValue, yValue, zValue);

Why don’t you use Vector3? seems silly not to use it when you need to define positions… Also from the look of it you seem to be new to C#? maybe programming in general? You should try read/watch some books/Tutorials/documentation. If you’re prefer video tutorials head over to YouTube load of in depths from “noob” to pro tutorials. If you prefer reading I can recommend “C# essentials” there’s a few of them don’t know all of them but the one I have is good and i think the others are good too! for online reading:
http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx
https://www.google.dk/search?q=C%23+tutorials&oq=C%23+tutorials&aqs=chrome.0.57j58j62l3.3522j0&sourceid=chrome&ie=UTF-8

  • Jackie

…i give up idk lol f*#$@k it

Can someone send me a link to a basic 2d game like space invaders ect…