public override bool IsInRange(FlutePlayer flutePlayer) { // is not null, assert! Transform camTrans = m_cam.transform; Vector3 pos = transform.position; Vector3 vec = pos - camTrans.position; // first check that it is in bounds // The offset is the projection of the vector on the camera surface // normalise it wrt. screen dimension Vector3 proj = m_cam.WorldToViewportPoint(pos); Vector2 screenVecProj = new Vector2(proj.x - 0.5f, proj.y - 0.5f); if (proj.z < 0 || screenVecProj.magnitude > maxOffset) { // Not a candidate. Return early, return(false); } RaycastHit hit; bool hasHit = Physics.Raycast( camTrans.position, vec.normalized, out hit, maxDistance, 0 ); // If the ray did not hit anything, or if the collider is this object's own. // This is done so that we don't require the interactive object to have a collider. return(!hasHit || hit.collider.gameObject == gameObject); }
static void Main(string[] args) { Musician[] Array = new Musician[3]; Array[0] = new ViolinPlayer(); // 왼쪽은 뮤지션객체, 오른쪽은 바이올린객체인데 오류가 안뜬다. Array[1] = new PianoPlayer(); Array[2] = new FlutePlayer(); for (int i = 0; i < Array.Length; ++i) { Array[i].Name(); Array[i].Instruments(); Console.WriteLine("********************"); } }
public abstract bool IsInRange(FlutePlayer flutePlayer);
public override bool IsInRange(FlutePlayer flutePlayer) { return(Vector3.Distance(flutePlayer.transform.position, transform.position) <= maxDistance); }
public void SetOwner(FlutePlayer aOwner) { Assert.IsNotNull(aOwner); owner = aOwner; }