void CheckRay() { Ray ray = Camera.main.ScreenPointToRay(pos.position); RaycastHit Hit; if (Physics.Raycast(ray, out Hit) && isBeingDragged) { objectHit = Hit.collider.gameObject; script = objectHit.GetComponent<ChangeMaterial>(); if (script != null) { if (isFirstInSequence && !script.isState1Done) script.ChangeToState1(); else if (!isFirstInSequence && script.isState1Done && !script.isState2Done) script.ChangeToState2(); Debug.Log(objectHit.name); } } }