First person controller will hit stupms with a ball, if the ball hits the stumps then the stupms will be dismanteled and hits are recorded in count variable.
I am new to unity3d .Please help
Regards
M.Qayyum
Edit:
I’m able to fire a ball from First Person Controller and hit this cube but i can’t able to detect that if cube is hit by ball or not.
Here is my script
public var ballPrefab : Transform;
public var ballSpeed : float = 1000;
function Update ()
{
if(Input.GetButtonDown("Fire1"))
{
if(!ballPrefab || !ballSpeed)
{
Debug.Log("[Shoot] 'ballPrefab' or 'ballSpeed' is undefined");
}
else
{
var ballCreate=Instantiate(ballPrefab, GameObject.Find("SpawnPoint").transform.position, Quaternion.identity);
ballCreate.rigidbody.AddForce(transform.forward * ballSpeed);
}
}
}
Well use a first person controller script (included with unity) and then make an action for when you press the button to “fire” and then just do an collision check to see if something hits the stump (which is a prefab). Then in your script make the log dismantle when it is hit with a method call. We cannot write the game for you, but this should give some direction. I would start with video tutorials on how to set up a basic game to know the basics of unity before you delve into this. It is quite daunting. well good luck
So the ball needs a sphere collider and the cube needs a box collider. If the cube also has a rigidbody it will automatically react to being hit. tag the ball with a new tag of “ball” and the stumps with “stumps” in the inspector.
To see the collision yourself write a function :
function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.tag == "ball"){
//do something like increment your counter
}
}
That would be attached to the stumps, if you want to attach to the ball change “ball” to “stumps”.