Several Questions - Help Needed

I was searching a lot in the forums, it´s a great tool for reference, but cannot find the rigth info for this issues:

  • How can I fix the frame rate so it could run at same speed on different computers? (It currently runs smooth on slow cpu but fast as hell on faster cpu)
  • How could you make differents intances of a gameobject? (I could make instances with Instantiate, but if i want that every instance fade out after some time, they all act as one, fading at same time, same happens if I try to destroy one of them)
  • If I try to acces the pixelInset of a GUITexture its says is not accesible. Same with location.x, etc. Is ther any way to access this variables directly?

Thanks!

You don’t want to do that. Look up Time.deltaTime, and use that for all movement. This way everything moves at the same speed on all framerates, but faster computers run more smoothly.

Instantiate does make different instances. How are you accessing them?

Not sure about your other question offhand. Welcome to the forums!

–Eric

Thanks!

  • I was wondering if there was any configuration to fix the framerate, but seems no. I´ll try the DeltaTime.

  • I use C#, and instantiate like:
    object = Instantiate(prefabLoadedinScene,…)

  • pixelInset is a group of variables of GUITexture, but I cannot acces this or location.x from script to change the value.

Thanks Again!

The pixelInset is a Rect, which is a struct. In C#, structs are passed by value, not by reference. So, to modify pixelInset’s members, you need to do:

Rect temp = guiTexture.pixelInset;
temp.xMin = 100f; // whatever modifications
guiTexture.pixelInset = temp;

It’s not Unity’s fault, it’s how C# is designed. If you use Unity’s JavaScript, you can just set guiTexture.pixelInset.xMin directly and it’ll just work. There is less typing in general with Unity’s JavaScript.

Cheers,
-Jon

There are actually a couple of ways to do that, but it’s really not what you want. :wink: Pretty much all games basically use a deltaTime-like method, even if you might specify an upper limit (common on consoles). Just multiply all movement by Time.deltaTime, like:

transform.Translate(Vector3.forward * speed * Time.deltaTime);

Hmm, can you provide some code that’s not working? Although my C# skillz are poor.

–Eric

Thanks Jonathan!.. that would help me a lot!
Thanks Eric too, I would use the deltaTime then…

For the instantiation… i have deleted the code for now, because the test were unsuccessful… but it was something like this:

public Circle circle;

void Start () {

//Circle
GameObject circle = GameObject.Find(“CircleOne”);
circle = (Circle)circle.GetComponent(“Circle”);

}

public void CreateCircle(float X, float Y, float Z)
{
Circle circleNew;
circleNew = Instantiate(circle, new Vector3(X,Y,Z), Quaternion.identity));
circleNew.Fade();
circleNew.Kill();

}

Thanks for all the answers! (and the Speed!)

Not sure I quite followed that (like I said, my C# doesn’t amount to much), but I think you want to instantiate an object from a prefab, not from a scene object. In Javascript:

var someObject : GameObject;

function Start() {
     var myObject : GameObject = Instantiate(someObject);
     // Do stuff with myObject
}

Then in the inspector, you drag the prefab onto the appropriate slot in the script.

–Eric

You are not instantiating a new object, but the the component from the same object. This must be why when you destroy one of them that all of them die (since you kill the gameObject attached to all of the Circle components).

To make them independent try:

    Circle newCircle = (Circle)((GameObject)Instantiate( circlePrefab ) ).GetComponent(typeof(Circle));

Btw, don’t use circle on both your vars (I’m not sure that even works, I think that to work you had to do this.circle = (Circle)circle.GetComponent(typeof(Circle)), but I may be mistaken).

Regards,
Afonso

THAT WORKS! Thanks Eric!
I’m just too wired to the code… I have to use the Unity Environment a little more…

I used a public variable and drag into the prefab.

Thanks to all!
I’m on my way now. :smile: