Esempio n. 1
0
    public void SetState(_celestialObject data)
    {
        rigidBody = this.gameObject.GetComponent <Rigidbody>();
        if (rigidBody == null)
        {
            rigidBody = this.gameObject.AddComponent(typeof(Rigidbody)) as Rigidbody;
        }
        staticBody = data.staticBody;
        velocity   = data.velocity;
        //rigidBody.position = data.position;
        transform.position = data.position;
        rigidBody.position = data.position;

        RotationSim rot = this.gameObject.GetComponent <RotationSim>();

        if (rot != null)
        {
            this.gameObject.GetComponent <RotationSim>().SetState(true);
            this.gameObject.GetComponent <RotationSim>().SetRotation(data.rotation[0], data.rotation[1]);
            this.gameObject.GetComponent <RotationSim>().StartRotation(true);
            this.gameObject.GetComponent <RotationSim>().Deploy();
        }
        else
        {
            this.gameObject.AddComponent(typeof(RotationSim));
            this.gameObject.GetComponent <RotationSim>().SetState(true);
            this.gameObject.GetComponent <RotationSim>().SetRotation(data.rotation[0], data.rotation[1]);
            this.gameObject.GetComponent <RotationSim>().StartRotation(true);
            this.gameObject.GetComponent <RotationSim>().Deploy();
        }

        mass           = data.mass;
        rigidBody.mass = mass;

        name = data.name;
        if (name != null)
        {
            txt = Resources.Load("PlanetNameText/PlanetName") as GameObject;
            Vector3 newpos = this.gameObject.transform.position;
            newpos = newpos + new Vector3(0f, 0.2f, 0f);
            txt    = Instantiate(txt, newpos, this.gameObject.transform.rotation);
            //txt.transform.SetParent(this.gameObject.transform, false);
            txt.AddComponent <PlanetNameMovement>();
            textTranslation = data.textTranslation;
            txt.GetComponent <PlanetNameMovement>().SetPlanet(this.gameObject, data.textTranslation);
            txt.GetComponent <TextMesh>().text = name;
        }

        if (staticBody)
        {
            rigidBody.isKinematic = true;
            this.gameObject.transform.position = data.position;
        }
        else
        {
            rigidBody.isKinematic = false;
        }
        gameObject.GetComponent <AudioSource>().Play();
        isShot = true;
    }
Esempio n. 2
0
    public _celestialObject(CelestialObject planet, int id)
    {
        this.id    = id;
        position   = planet.GetPosition();
        velocity   = planet.velocity;
        staticBody = planet.staticBody;
        mass       = planet.mass;

        RotationSim rot = planet.gameObject.GetComponent <RotationSim>();

        if (rot != null)
        {
            rotation = rot.GetRotation();
        }
        else
        {
            rotation = new float[] { 0f, 0f };
        }

        name             = planet.GetName();
        textTranslation  = planet.textTranslation;
        weightMultiplier = planet.weightMultiplier;
    }