i need help with the on collision script of rigidbody.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript1 : MonoBehaviour
{
public GameObject holeaccess;
public NewBehaviourScript holescript;
public Rigidbody2D ball;
public Vector2 holepos;
public int updatestop = 2;

bool check = true;





public Vector2 force = new Vector2(0, 300);


// Use this for initialization
void Start()
{
    holeaccess = GameObject.FindGameObjectWithTag("holeimage");
    holescript = holeaccess.GetComponent<NewBehaviourScript>();

     

    ball = GetComponent<Rigidbody2D>();

    NewBehaviourScript m = GetComponent<NewBehaviourScript>();

}

// Update is called once per frame
void Update()
{
    if (check == true)
    {
        holepos = holescript.pos;

        if (Input.GetKeyUp("space"))
        {
            ball.velocity = Vector2.zero;

            ball.AddForce(force);
        }

    }
    

}
void OnTriggerEnter(Collider other)
{

    ball.position.Set(holepos.x,holepos.y);
    check=false;
   ball.gravityScale
 
}

}

In the above script i want to set the ball position to hole postion when they collide.
The hole is in other script.
Also i want to disable gravity on collision.
I have checked istrigger to disable default collision effect.
What am i doing wrong here please help.
i am not able to disable gravity nor am able to reset ball`s position.
Please help.

2 Answers

2

You appear to have a Rigidbody2D, not a Rigidbody.

In which case, you’ll want to implement OnTriggerEnter2D(Collider 2D other), not OnTriggerEnter.

Thanks.
I missed that.

Probably didn't add a description to the asset either lol