So what im trying to do is send a message to a other script and have it send how much damage to cause it and to call a function.
heres the sending script
public int speed = 5;
public Transform hold;
public Transform aim;
public bool aiming = false;
public float FireRate;
public RaycastHit hit;
public GameObject Barrel;
public int dammage;
void Start() {
InvokeRepeating("fire", 2, FireRate);
}
// Update is called once per frame
void FixedUpdate ()
{
if(Input.GetKey(KeyCode.Mouse1))
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, aim.position, step);
}
else
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, hold.position, step);
}
if(Input.GetKey(KeyCode.Mouse0))
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
print("MouseLook button down");
if (Physics.Raycast(Barrel.transform.position, fwd, 1000))
{
hit.collider.SendMessage("hit", SendMessageOptions.DontRequireReceiver);
print("fired");
}
}
}
}
here is the receiving script
public float hp = 2.0f;
public void hit()
{
hp-=1;
if(hp<=0)
{
Destroy(gameObject);
}
}
Are you having any specific problem or do you have a question?
– mattyman174