Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink
Go down
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 1230
Rep : 0
Join date : 2015-03-12
View user profile

Throw Ball to hit a Spot

on Thu Mar 12, 2015 6:25 am
Hi guys,

I am new to Unity and trying to make a game to throw ball, I wrote the below code, but now I want the ball to hit the spot named "BallThrowPoint" and then go hit the target accordingly.


using UnityEngine;
using System.Collections;

public class Throwball2 : MonoBehaviour {
   GameObject prefab;

   void Start()
      prefab = Resources.Load ("myball") as GameObject;
   void  Update (){
      if (Input.GetMouseButtonDown (0)) {
         GameObject myball = Instantiate(prefab) as GameObject;
         myball.transform.position = transform.position + Camera.main.transform.forward * 2;
         Rigidbody rb = myball.GetComponent<Rigidbody>();
         rb.velocity = Camera.main.transform.forward * 40;


Pls help,

Thanks in advance.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum