public void ShootGreen() { RaycastHit hit; if (Physics.Raycast(bulletPoint.transform.position, bulletPoint.transform.forward, out hit, range)) //(position of bullet point,forward from bullet point position, shoot, within certain range) { Debug.Log(hit.transform.name); ChangeMaterial changeMaterial = hit.transform.GetComponent <ChangeMaterial>(); if (changeMaterial != null) { changeMaterial.ColourGreen(); } } }