public void SetMission(Nip nip, Mission.Type type, int count) { var mission = missions.Find(m => m.Nip.GetName() == nip.GetName() && m.type == type); if (mission == null) { return; } if (type == Mission.Type.Collect) { var allNips = new List <GameObject>(GameObject.FindGameObjectsWithTag("nip")); var nips = allNips.FindAll(n => { return(n.GetComponent <Nip>().GetName() == nip.GetName()); }); mission.count = nips.Count; } mission.count += count; if (mission.count < 0) { mission.count = 0; } if (mission.IsComplete()) { var anim = Resources.Load <GameObject>("Animations/MissionComplete"); var canvas = GameObject.Find("Canvas"); if (canvas == null) { return; } Instantiate(anim, canvas.transform); stars += 1; var newGrade = mission.Nip.Grade + 1; if (newGrade > currentGrade) { currentGrade = newGrade; } missions.Remove(mission); GenerateMission(); var starController = FindObjectOfType <StarController>(); if (starController) { starController.clickable = true; } } }
private bool IsValidHit(RaycastHit hit, Nip nip) { var cell = hit.collider.GetComponent <Cell>(); if (cell && cell.isPrison) { return(false); } if (cell.transform.childCount > 0) { var powder = cell.GetComponentInChildren <Powder>(); var mine = cell.GetComponentInChildren <Mine>(); var requriedNip = ( nip == null ? false : nip.GetName() == cell.GetComponentInChildren <Nip>()?.GetName() ); if (requriedNip && cell.transform.childCount == 1) { } // allow move for specific nips else if (powder) { } else if (mine) { } // no allow move else { return(false); } } ; return(true); }
public Nip GetClosestNip(Nip nip) { var nips = new List <Nip>(GameObject.FindObjectsOfType <Nip>()).FindAll(obj => { return(nip.GetName() == obj.GetName()); }); if (nips.Count == 0) { return(null); } var destination = nips[0]; foreach (var obj in nips) { var currentDist = Vector3.Distance(this.transform.parent.position, destination.transform.position); var newDist = Vector3.Distance(this.transform.parent.position, obj.transform.parent.position); if (newDist < currentDist) { destination = obj; } } return(destination); }