I been studying c# and unity a lot more lately i mostly been off and on but now im serious, and stuck.
I been following tutorials on cgcookie and im confused around the start function. why is it unessacry? i can comment out the GetComponent and it works just fine but how?
the best idea for why is that it finds the component a other way in the update function.
But im not sure how or what exacly makes GetComponent unnessacry?
Im still new to c# & unity so i wont be able to understand anything to advanced sry!
I am slighty aware clone is a Rigidbody type but im not sure how it connects to the component of Rigidbody is it the “as rigidbody” part?
`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cannonball : MonoBehaviour {
public Rigidbody projectile;
public int throwPower;
// Use this for initialization
void Start () {
//projectile = projectile.GetComponent ();
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown(“Fire1”)) {
Rigidbody clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection (Vector3.forward * throwPower);
}
}
}`
If you want to know about the scene the object the script is connected to is a empty game object and the script shoots a ball prefab from it. I dont want to show any screen shots of the scene for respects for cgcookie.