- Home /
How to add a Rigid body and a box collider component to a Texture2D object
I am trying to make a snake game. the code is not all mine. I have learnt many things from here and there... My problem is that, The tutorial game is very basic and it is not doing anything like collision detection and other things like wall checking or different levels. I am a beginner and want to do 1 thing that will make my work done. All snake head, piece, food, even the background is made by Texture2D. I want the head of the snake detects 2D collisions with it. which is now getting detect by Rect.contains method. but I don't want it like that, I want to detect collisions by onTriggerEnter() method for which I need a to add BoxCollider with my snakeHead. Kindly Help me. if this is possible.
Answer by KhShani · Mar 26, 2014 at 09:40 AM
pyare bhai create a new quad or plane... in inspector drop your texture into that. you can also assign colliders,rigidbodies to that
Thanks bro. $$anonymous$$y problem is not related to what you are saying. Can Someone please tell how to add physics components to the texture2D through code. I don't have anything on game scene. Everything is being drawn on the fly.
Well just add a collider component to the elements you want to collide and check the IsTrigger checkbox, then you can use OnTriggerEnter() in the scripts attached to one or the other element.
Your answer
![](https://koobas.hobune.stream/wayback/20220613141211im_/https://answers.unity.com/themes/thub/images/avi.jpg)