Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Coordinates from Object to coordinates of Bullet

Discussion in 'Scripting' started by DrunkBearzz, Oct 6, 2014.

  1. DrunkBearzz

    DrunkBearzz

    Joined:
    Oct 6, 2014
    Posts:
    3
    So I have 2 classes: 1.)Object
    2.)Bullet

    Now I need to track the x,y,z coordinates of Object and make it same as x,y,z coordinates of bullet so my ship could shoot from where the object is. I have no idea how to make that transaction between classes.

    (Im using vector 3 with z = 0 becouse it's 2d game)

    Thanks in advance.
     
  2. Pirs01

    Pirs01

    Joined:
    Sep 30, 2012
    Posts:
    389
    Code (csharp):
    1. Object.position = Bullet.position;
    Assuming of course the field in question is static - makes no sens to talk about setting value to class field otherwise.
     
  3. DrunkBearzz

    DrunkBearzz

    Joined:
    Oct 6, 2014
    Posts:
    3
    Thanks man, I'm gonna try this when I get home.
     
  4. Pirs01

    Pirs01

    Joined:
    Sep 30, 2012
    Posts:
    389
    It's not the best idea to call your class Object though. Not only it's ambiguous but there already is such class defined in UnityEngine namespace: http://docs.unity3d.com/ScriptReference/Object.html

    Also while I did anwser your question I get a feeling you didn't frame it precisly at all. Make sure you understand the deifference between class and an object: http://stackoverflow.com/questions/8550130/what-is-the-difference-between-objects-and-classes-in-c
    In fact make sure you understand classes in general: http://msdn.microsoft.com/en-us/library/ms173109.aspx and C# language in general: http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx
     
  5. DrunkBearzz

    DrunkBearzz

    Joined:
    Oct 6, 2014
    Posts:
    3
    I couldn't figured it out for 2 days than I just put it in one script. Let's just say that it's 10x more easier to track transformations that way.I wasted 2 days on something I figured out in 10 min...Programming man :D

    Thanks for help
     
    Last edited: Oct 8, 2014