- Home /
Bounce value not change in script for 2D object in Unity4.3.
Hi, I am working on unity4.3 and facing few strange responses. First it was ray cast as I already posted question. Now I couldn't change the value of bounce of 2D object in script. I have 2D object in which I added physic material and set bounce value to 0.9 but I want when this object collide with any foam material then it will reduce down to 0.3 so that it look like real. I am doing like this "collider2D.sharedMaterial.bounciness=0.3f" but its bouncing same as it is as it was 0.9. I also logged this after changing value and it shows 0.3, value is changed but bounces is not changed. Is this bug of Unity3d or I have to do some thing different way to change value. Kindly suggest me if anyone experienced this. Thanks in advance.
Answer by hamstar · Dec 11, 2013 at 08:59 AM
This is a bug in Unity3D. I experienced the same problem. A workaround was posted here, which is to disable and then re-enable the collider in order for the changes to take affect.
For example:
collider2D.sharedMaterial.bounciness = 0.3f;
collider2D.enabled = false;
collider2D.enabled = true;
@hamstar, Thats great u saved my day... Could you please tell me that is this possible that I can move object when I only touch or pick that desired object in 2D. Some one suggested my ray cast but I didn't work by doing that. Here is my code which move object when swipe on whole screen if(Input.touchCount>0 && Input.GetTouch(0).phase == TouchPhase.$$anonymous$$oved) { print("swiped............"); isSwiped=true; Vector2 touchdeltaposition = Input.GetTouch(0).deltaPosition; anglex = (float) (touchdeltaposition.x * Time.deltaTime 10.0); angley = (float) (touchdeltaposition.y Time.deltaTime *10.0); elevationAngle = new Vector3(anglex,angley,0); Vector3 elevation = Quaternion.Euler(elevationAngle)*transform.forward; rigidbody2D.AddForce(elevation); rigidbody2D.velocity= new Vector2(anglex,angley);
}
I just want to move object when swipe occur only on that object. Is this also Unity bug or I am doing wrong. Here is my question for moving but It didn't work out. http://answers.unity3d.com/questions/589421/detect-touched-2d-object-in-unity3d-43.html. Thanks for your reply.
Sorry I don't really know. Before I've done it with a Raycast, which robertu says doesn't work with 2D colliders. I guess this could work, but it might not be the best solution.
if (Input.touchCount > 0) {
if(renderer.bounds.Contains(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position))) {
// select me
}
}