I want to try a project that only have one Script file (like AS3), so everything is done but when I imagine about collision, I don’t know what must I do. I read everywhere in Google just found OnCollisionEnter but it need to attach the script to one object, that I want is OnCollisionEnter in void Update and can link object like Ball that only get that OnCollisionEnter.
I can add multiple object to be attached in one script with public GameObject anyObject;
Didn’t Understand? Just add a comment
The docs say it’s MonoBehaviour.OnCollisionEnter. This means, it’ll only detect collisions of the current object the script is attached to. It will not detect collisions on other gameObjects.
–David–
so, is there any collision detector in void Update?
– SalveNo, it doesn't work that way.
– Gonnellayea if your saying you want 1 script where you tell it what to do if a ball collides and then what to do as well if a box does and also if a player does.
All in one script. Nope.
Also that is simply bad programming from an object oriented point of view.
Each object should deal with it’s own self.
With the way your talking about designing it the ball doesn’t work unless this script that deals with 30 different objects collisions is included.
Thats like me saying i’d like a calculator that does addition and you saying I can’t give you that unless it also does division graphing and provides home phone service.
In as much as possible objects should be self contained and they should be able to be taken out and put in and not break the entire thing. Minimize the amount of dependencies you have.
Too much script file make me confuse and It was harder to modify variable, that is why I choose to make it in One Script. And also this project is a test project, not real project. I create the test project for gaining Exp and Leveling Up and make everything easier.
– Salve© 2022 - 2024 — McMap. All rights reserved.
so i am guessing, void OnCollisionEnter(Collision coll) { foreach (ContactPoint cpoint in coll.contacts) { print(cpoint.otherCollider.name); } }
– Varickcan you give me a detail of the script, like difference foreach and if and what will "(ContactPoint cpoint in coll.contacts)" means, and what other thing that must I do to make the collision detector work? I already create the script and attach it to the ball, when I collide with box, nothing printed.
– SalveYou can't**.** Accept David's answer and close this.
– Noctambulism