Комментарии:
This code really helped me back when I started. I'm sure there are ways to improve it, but this little guy does quite a lot, hope it helps :)
{
public GameObject deathExplosion;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "environment")
{
GameObject deathObj = Instantiate(deathExplosion, transform.position, transform.rotation) as GameObject;
Explosion deathScript = deathObj.GetComponent<Explosion>();
deathScript.sizeGoal = 80;
Destroy(gameObject);
}
}
}
Guys, anyone good at code? even chatgpt cant get me out of this one, i dont want to drag the prefab to a open variable of GameObject in the inspector, i want to do it by code, the prefab is in Assets/Prefabs/GoHadouken.prefab....any clue?
goHadoukenPrefab = (GameObject)Resources.Load("Assets/Prefabs/GoHadouken", typeof(GameObject)); this isnt working at all....any help is welcome
Good video, simple and straightforward. Thanks!
ОтветитьThank you very much, you helped me a lot. I am a beginner and you really told me exactly what I needed in the first sentence. You are great, thank you again.And so many of them are blabbering on,on You Tube- without saying the essence, I could hardly find the simple thing I needed. How effects prefab to put in the code! .. So easy and so complicated to find. Again, thank you !!
ОтветитьSome of the best unity tutorials I've ever seen. Thanks man.
ОтветитьWhy are you using cast?
ОтветитьThank you isn't enough for what your channel has been make for all this time
ОтветитьThe only channel i forgot to comment
ОтветитьYou should make a tutorial on how to play noises
ОтветитьMerci.
ОтветитьAddressable and aaset reference save memory!
Ответитьyes
ОтветитьI'm one whole hour late :( I'll do better next time
ОтветитьBeen watching you for a few months now. You have the best teaching style out of anyone I have seen on this platform (and Udemy). I appreciate the energy and the short and easy to follow explanations (and not making me beat my head on the table waiting for the info to stick). Especially for an intermediate 3d designer/ game developer.
I'll be back every time:)
Thanks for teaching us! If I make it big I will not forget
ОтветитьOutro song is super catchy. Is it your composition?
ОтветитьMan, this really helps me figure out how to achieve my animation for leveling up. I was a bit confused about how I was going to tackle it, but now I'm absolutely pumped. THANK YOU!
ОтветитьHey royalskies are u ever thinking of doing a vid on playmaker someday? (It's a visual scripting asset for non-coders).
Seems like it's useful for only simple stuff but it looks kinda interesting.
useful
ОтветитьIf you notice, Visual Studio faded out the "as GameObject" in your code. This is because Instantiate is a generic method, and will automatically set its return type to the same type as the declared type of the thing being instantiated. So if you're instantiating a variable declared as a GameObject, then the return type will be GameObject already, so there's no need to cast it to GameObject.
ОтветитьYou can make the code much cleaner by putting all the garbage in an static method:
public static void ExplodeObject(GameObject prefab, Transform t, float size = 20.0f)
{
var obj = Instantiate(prefab, t.position, t.rotation) as GameObject;
var exp = obj.GetComponent<Explosion>();
if(exp == null)
throw new Exception("Blah, blah, blah, incorrect prefab or something :|");
exp.sizeGoal = size;
Destroy(t.gameObject);
}
And you'd use it like so:
void OnTriggerEnter(Collider c) // c instead of other because the name of the variable doesn't matter, the type matters.
{
if(c.gameObject.CompareTag("environment")) // I'm starting think you're using string comparison instead of tag comparison on purpose...
Explosion.ExplodeObject(deathExplosion, transform, 80.0f);
}
This essentially does the exact same thing, plus check that the prefab's root object does indeed have an Explosion component, but it's much cleaner, there isn't a way to make everything cleaner here, not that I can think of off the top of my head, but moving all the clutter from the Player class into the Explosion class, we're hiding it underneath something we're rarely gonna touch after the matter if at all.
Something else I wanted to say is that it may be worth doing a very basic tutorial on doing custom inspectors, since this is something that would benefit from it, in that you can expose the deathExplosion variable, but before assigning it to whatever the user dragged or whatever, you can then check if it has an Explosion component, and if not just do nothing, otherwise set it as you'd normally do, you can also make the inspector pretty, put things in tabs with toolbars and stuff! And it's actually quite a bit simpler than you'd think, I can provide a couple examples if anyone wants it, otherwise it can be looked up on internet, there's plenty tutorials and articles on it.
Second!
ОтветитьHi
Ответить