In this scene there are two boxes when user press space key box1 collide with other box then score increment. But the problem which i faces, one is when box1 collide with other box then box1 drops on the ground and it's position values doesn't stop. Second is when score increment how to respawn that box1 again.
public class box1 : MonoBehaviour {
Rigidbody2D rigid;
void Start () {
rigid = GetComponent<Rigidbody2D> ();
rigid.isKinematic = true;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Space)) {
rigid.isKinematic = false;
}
}
}
Box 2:
public class boxer2 : MonoBehaviour {
public int timeshit;
public Text texter;
// Use this for initialization
void Start () {
timeshit = 0;
texter.text = "Score Fall : " + timeshit;
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D(Collision2D other){
timeshit++;
texter.text = "Score Fall : " + timeshit;
}
}
New Code Updated :
public class boxer2 : MonoBehaviour {
public GameObject boxObj;
public int timeshit;
public Text texter;
void Start () {
timeshit = 0;
texter.text = "Score Fall : " + timeshit;
}
void Update () {
}
void OnCollisionEnter2D(Collision2D col){
timeshit++;
texter.text = "Score Fall : " + timeshit;
if (col.gameObject.tag == "Player") {
Destroy(col.gameObject,0.5f);
}
Instantiate(boxObj, new Vector3(0.04f, 0f, 0f), Quaternion.identity);
}
}


