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

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » Throw Ball to hit a Spot

Throw Ball to hit a Spot

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Throw Ball to hit a Spot on Thu Mar 12, 2015 6:25 am

nyt1972


Member [Lv. 0]
Member [Lv. 0]
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.

Code:

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.

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum