I am making a script to call variables from the object which hits the targets to calculate force. But, I was wondering if there was a simple way to make a private variable to that GameObject and later to be able to access it like you can do with transform.
In tranform you can do
terrain.transform or this.transform
I want to be able to access a variable like that be able to do.
var bulletWeight : float = GameObject.Find(“Bullet”).weight;
bullet.mass etc.
Is there a way to do this? Without making a script to assign the value and then accessing that script value and calling it from there? I rather not do it this way unless I have too.
You’ll have to do it via attached script classes (which can be attached as ‘components.’) Even the basic Gameobject is class that is a collection of other classes and structs (such as transform.)
Simple class example (c#)
using UnityEngine;
using System.Collections;
public class bullet : MonoBehaviour {
float weight;
float speed;
}