├── .github └── workflows │ └── dotnet.yml ├── ActivateVFX.cs ├── AdsManager.cs ├── AlarmManager.cs ├── CameraDistance.cs ├── CameraShake.cs ├── CoinManager.cs ├── DamgeToPlayer.cs ├── DayAndNight.cs ├── DeleteAlarm.cs ├── EnemyAI.cs ├── EnemyDamage.cs ├── ItemDrop.cs ├── NotificationManager.cs ├── Photon Unity Networking ├── NetwookPooling.cs ├── NeworkObservable.cs ├── PhotonLobby.cs └── PhotonLobbyCustomMatch.cs ├── PlayerManager.cs ├── PoolSystem.cs ├── PowerUp.cs ├── README.md ├── RandomSpawnInACircle.cs ├── RatAI.cs ├── Rotator.cs ├── SavedAlarm.cs ├── ScrollSelect.cs ├── UITest.cs └── WatchManager.cs /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a .NET project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net 3 | 4 | name: .NET 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | - name: Setup .NET 20 | uses: actions/setup-dotnet@v4 21 | with: 22 | dotnet-version: 8.0.x 23 | - name: Restore dependencies 24 | run: dotnet restore 25 | - name: Build 26 | run: dotnet build --no-restore 27 | - name: Test 28 | run: dotnet test --no-build --verbosity normal 29 | -------------------------------------------------------------------------------- /ActivateVFX.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ActivateVFX : MonoBehaviour 6 | { 7 | 8 | public GameObject vfx; 9 | // Start is called before the first frame update 10 | private void OnTriggerEnter(Collider other) 11 | { 12 | if(other.gameObject.CompareTag("Player")) 13 | { 14 | vfx.SetActive(true); 15 | } 16 | } 17 | 18 | private void OnTriggerExit(Collider other) 19 | { 20 | if (other.gameObject.CompareTag("Player")) 21 | { 22 | StartCoroutine(VFXDisable()); 23 | } 24 | } 25 | 26 | IEnumerator VFXDisable() 27 | { 28 | yield return new WaitForSeconds(2f); 29 | vfx.SetActive(false); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AdsManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using GoogleMobileAds.Api; 5 | using System; 6 | 7 | public class AdsManager : MonoBehaviour 8 | { 9 | public static AdsManager ads; 10 | private BannerView bannerView; 11 | private RewardedAd rewardedAd; 12 | 13 | [Header("AD ID")] 14 | [SerializeField]string adUnitId = "************************************"; 15 | [SerializeField] string rewardedAdUnitId = "************************************"; 16 | 17 | private Player player; 18 | private void Awake() 19 | { 20 | if(ads == null) 21 | { 22 | ads = this; 23 | } 24 | } 25 | // Start is called before the first frame update 26 | void Start() 27 | { 28 | player = Player.instance; 29 | // Initialize the Google Mobile Ads SDK. 30 | MobileAds.Initialize(initStatus => { }); 31 | 32 | this.RequestBanner(); 33 | this.rewardedAd = new RewardedAd(rewardedAdUnitId); 34 | } 35 | 36 | private void RequestBanner() 37 | { 38 | /*#if UNITY_ANDROID 39 | 40 | #elif UNITY_IPHONE 41 | string adUnitId = "ca-app-pub-3940256099942544/2934735716"; 42 | #else 43 | string adUnitId = "unexpected_platform"; 44 | #endif */ 45 | 46 | // Create a 320x50 banner at the top of the screen. 47 | //this.bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom); 48 | this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom); 49 | 50 | // Create an empty ad request. 51 | AdRequest request = new AdRequest.Builder().Build(); 52 | 53 | // Load the banner with the request. 54 | this.bannerView.LoadAd(request); 55 | } 56 | 57 | public void LoadRewardedAds() 58 | { 59 | 60 | // Create an empty ad request. 61 | //AdRequest request = new AdRequest.Builder().Build(); 62 | // Load the rewarded ad with the request. 63 | //this.rewardedAd = new RewardedAd(rewardedAdUnitId); 64 | 65 | // Called when an ad request has successfully loaded. 66 | this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded; 67 | // Called when an ad request failed to load. 68 | this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad; 69 | // Called when an ad is shown. 70 | this.rewardedAd.OnAdOpening += HandleRewardedAdOpening; 71 | // Called when an ad request failed to show. 72 | this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow; 73 | // Called when the user should be rewarded for interacting with the ad. 74 | this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward; 75 | // Called when the ad is closed. 76 | this.rewardedAd.OnAdClosed += HandleRewardedAdClosed; 77 | 78 | // Create an empty ad request. 79 | AdRequest request = new AdRequest.Builder().Build(); 80 | // Load the rewarded ad with the request. 81 | this.rewardedAd.LoadAd(request); 82 | } 83 | 84 | public void HandleRewardedAdLoaded(object sender, EventArgs args) 85 | { 86 | MonoBehaviour.print("HandleRewardedAdLoaded event received"); 87 | UserChoseToWatchAd(); 88 | player.CancleDied(); 89 | } 90 | 91 | public void HandleRewardedAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) 92 | { 93 | MonoBehaviour.print( 94 | "HandleRewardedAdFailedToLoad event received with message: " 95 | + args.LoadAdError.GetMessage()); 96 | player.playerDied(); 97 | } 98 | 99 | public void HandleRewardedAdOpening(object sender, EventArgs args) 100 | { 101 | MonoBehaviour.print("HandleRewardedAdOpening event received"); 102 | player.CancleDied(); 103 | } 104 | 105 | public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args) 106 | { 107 | MonoBehaviour.print( 108 | "HandleRewardedAdFailedToShow event received with message: " 109 | + args.AdError.GetMessage()); 110 | player.playerDied(); 111 | } 112 | 113 | public void HandleRewardedAdClosed(object sender, EventArgs args) 114 | { 115 | MonoBehaviour.print("HandleRewardedAdClosed event received"); 116 | } 117 | 118 | public void HandleUserEarnedReward(object sender, Reward args) 119 | { 120 | player.RespawnSuccess(); 121 | } 122 | 123 | private void UserChoseToWatchAd() 124 | { 125 | if (this.rewardedAd.IsLoaded()) 126 | { 127 | this.rewardedAd.Show(); 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /AlarmManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | using System; 6 | 7 | public class AlarmManager : MonoBehaviour 8 | { 9 | [Serializable] 10 | public class MyAlarms 11 | { 12 | public List AlarmName = new List(); 13 | public List AlarmDesign = new List(); 14 | public List AlarmHour = new List(); 15 | public List AlarmMinutes = new List(); 16 | public List AlarmSet = new List(); 17 | //public bool set; 18 | 19 | } 20 | public MyAlarms alarms; 21 | 22 | [Serializable] 23 | public class SnoozeDuration 24 | { 25 | public float snoozetimeduration; 26 | public GameObject checker15; 27 | public GameObject checker30; 28 | public GameObject checker45; 29 | 30 | } 31 | public SnoozeDuration SD; 32 | 33 | public int hours; 34 | public int minutes; 35 | public int seconds; 36 | string design; 37 | public string h; 38 | public int HH; 39 | public int alarmHr; 40 | public int alarmMm; 41 | public Text alarmHrText; 42 | public Text alarmMmText; 43 | public string alarmDesign; 44 | public GameObject checkerPM; 45 | public GameObject checkerAM; 46 | public GameObject Alarm; 47 | public GameObject Home; 48 | public GameObject Settings; 49 | public GameObject SetAlarmp; 50 | public GameObject Timep; 51 | public GameObject MyAlarm; 52 | 53 | public Text AlarmNameField; 54 | 55 | public Text AN; 56 | public Text AT; 57 | public GameObject content; 58 | public GameObject alarmSave; 59 | public int indexSave; 60 | public int Savelistcount; 61 | public int AlarmedSaved; 62 | public int DeleteIndex; 63 | //public Text AH; 64 | //public Text AM; 65 | 66 | public float countdown; 67 | public float snoozetime; 68 | public bool snoozee; 69 | public int indexCheck; 70 | 71 | 72 | 73 | void Awake () 74 | { 75 | if(Application.isEditor) 76 | { 77 | Application.runInBackground = true; 78 | } 79 | StartCoroutine("SetAlarmText"); 80 | 81 | // alarms.AlarmHour = PlayerPrefs.GetInt("AlarmHour"); 82 | // alarms.AlarmMinutes = PlayerPrefs.GetInt("AlarmMinutes"); 83 | // alarms.AlarmDesign = PlayerPrefs.GetString("AlarmDesign"); 84 | //alarms.AlarmName = PlayerPrefs.GetString("AlarmName"); 85 | } 86 | 87 | // Start is called before the first frame update 88 | void Start() 89 | { 90 | LoadAlarm(); 91 | countdown = snoozetime = 900.0f; 92 | //alarmHr = hours; 93 | //alarmMm = minutes; 94 | //alarmDesign = design; 95 | StartCoroutine("SetAlarmText"); 96 | } 97 | 98 | // Update is called once per frame 99 | void FixedUpdate() 100 | { 101 | System.DateTime time = System.DateTime.Now; 102 | 103 | h = time.ToString("hh"); 104 | hours = System.Convert.ToInt32(h); 105 | minutes = time.Minute; 106 | seconds = time.Second; 107 | design = time.ToString("tt"); 108 | HH = time.Hour; 109 | alarmHrText.text = alarmHr.ToString("D2"); 110 | alarmMmText.text = alarmMm.ToString("D2"); 111 | //AN.text = alarms.AlarmName; 112 | //AD.text = alarms.AlarmDesign; 113 | //AH.text = alarms.AlarmHour.ToString(); 114 | //AM.text = alarms.AlarmMinutes.ToString("D2"); 115 | 116 | 117 | 118 | CheckAlarm(); 119 | SnoozeManager(); 120 | 121 | 122 | PlayerPrefs.SetInt("AlarmSaved", Savelistcount); 123 | 124 | } 125 | 126 | 127 | public void AddHr() 128 | { 129 | alarmHr++; 130 | if(alarmHr > 12) 131 | { 132 | alarmHr = 1; 133 | } 134 | 135 | } 136 | 137 | public void SubHr() 138 | { 139 | alarmHr--; 140 | 141 | if(alarmHr < 1) 142 | { 143 | alarmHr = 12; 144 | } 145 | 146 | } 147 | 148 | public void AddMm() 149 | { 150 | alarmMm++; 151 | if(alarmMm > 59) 152 | { 153 | alarmMm = 0; 154 | } 155 | 156 | } 157 | 158 | public void SubMm() 159 | { 160 | alarmMm--; 161 | if(alarmMm < 0) 162 | { 163 | alarmMm = 59; 164 | } 165 | 166 | } 167 | 168 | public void DesignOperation1() 169 | { 170 | if(alarmDesign == ("AM")) 171 | { 172 | alarmDesign = ("PM"); 173 | checkerAM.SetActive(false); 174 | checkerPM.SetActive(true); 175 | } 176 | } 177 | 178 | public void DesignOperation2() 179 | { 180 | if(alarmDesign == ("PM")) 181 | { 182 | alarmDesign = ("AM"); 183 | checkerAM.SetActive(true); 184 | checkerPM.SetActive(false); 185 | } 186 | } 187 | 188 | public void SetAlarm() 189 | { 190 | /*alarms.AlarmHour = alarmHr; 191 | alarms.AlarmMinutes = alarmMm; 192 | alarms.AlarmDesign = alarmDesign; 193 | alarms.AlarmName = AlarmNameField.text.ToString(); 194 | 195 | PlayerPrefs.SetInt("AlarmHour", alarms.AlarmHour); 196 | PlayerPrefs.SetInt("AlarmMinutes", alarms.AlarmMinutes); 197 | PlayerPrefs.SetString("AlarmDesign", alarms.AlarmDesign); 198 | PlayerPrefs.SetString("AlarmName", alarms.AlarmName); */ 199 | alarms.AlarmHour.Add(alarmHr); 200 | alarms.AlarmMinutes.Add(alarmMm); 201 | alarms.AlarmDesign.Add(alarmDesign); 202 | alarms.AlarmName.Add(AlarmNameField.text); 203 | alarms.AlarmSet.Add(1); 204 | //alarms.set = true; 205 | 206 | for(int i = AlarmedSaved; i < alarms.AlarmName.Count && i < alarms.AlarmHour.Count && i < alarms.AlarmMinutes.Count && i < alarms.AlarmDesign.Count && i < alarms.AlarmSet.Count; i++) 207 | { 208 | 209 | PlayerPrefs.SetString("AlarmNames" + i, alarms.AlarmName[i]); 210 | PlayerPrefs.SetString("AlarmDesigns" + i, alarms.AlarmDesign[i]); 211 | PlayerPrefs.SetInt("AlarmMinutes" + i, alarms.AlarmMinutes[i]); 212 | PlayerPrefs.SetInt("AlarmHours" + i, alarms.AlarmHour[i]); 213 | PlayerPrefs.SetInt("AlarmSet" + i, alarms.AlarmSet[i]); 214 | 215 | //DeleteAlarm(i); 216 | indexSave = i; 217 | 218 | 219 | } 220 | 221 | AN.text = alarms.AlarmName[indexSave]; 222 | AT.text = alarms.AlarmHour[indexSave].ToString("D2") + ":" + alarms.AlarmMinutes[indexSave].ToString("D2") + alarms.AlarmDesign[indexSave]; 223 | 224 | var copy = Instantiate(alarmSave); 225 | copy.transform.SetParent(content.transform); 226 | copy.transform.localPosition = Vector3.zero; 227 | AlarmedSaved++; 228 | DeleteIndex++; 229 | 230 | PlayerPrefs.SetInt("CountAlarmName", alarms.AlarmName.Count); 231 | PlayerPrefs.SetInt("CountAlarmMinutes", alarms.AlarmMinutes.Count); 232 | PlayerPrefs.SetInt("CountAlarmHour", alarms.AlarmHour.Count); 233 | PlayerPrefs.SetInt("CountAlarmDesign", alarms.AlarmDesign.Count); 234 | PlayerPrefs.SetInt("CountSet", alarms.AlarmSet.Count); 235 | 236 | PlayerPrefs.SetInt("AlarmSaved", AlarmedSaved); 237 | PlayerPrefs.Save(); 238 | 239 | } 240 | 241 | public void LoadAlarm() 242 | { 243 | Savelistcount = PlayerPrefs.GetInt("CountAlarmName"); 244 | 245 | for(int i = 0; i < Savelistcount; i++) 246 | { 247 | string alarmN = PlayerPrefs.GetString("AlarmNames" + i); 248 | string alarmD = PlayerPrefs.GetString("AlarmDesigns" + i); 249 | int alarmM = PlayerPrefs.GetInt("AlarmMinutes" + i); 250 | int alarmH = PlayerPrefs.GetInt("AlarmHours" + i); 251 | int alarmS = PlayerPrefs.GetInt("AlarmSet" + i); 252 | alarms.AlarmHour.Add(alarmH); 253 | alarms.AlarmMinutes.Add(alarmM); 254 | alarms.AlarmDesign.Add(alarmD); 255 | alarms.AlarmName.Add(alarmN); 256 | alarms.AlarmSet.Add(alarmS); 257 | AN.text = alarmN; 258 | AT.text = alarmH.ToString("D2") + ":" + alarmM.ToString("D2") + alarmD; 259 | 260 | var copy = Instantiate(alarmSave); 261 | copy.transform.SetParent(content.transform); 262 | copy.transform.localPosition = Vector3.zero; 263 | DeleteIndex = i; 264 | indexSave = i; 265 | } 266 | AlarmedSaved = PlayerPrefs.GetInt("AlarmSaved"); 267 | } 268 | 269 | 270 | 271 | void CheckAlarm() 272 | { 273 | for (int i = 0; i < alarms.AlarmDesign.Count && i < alarms.AlarmHour.Count && i < alarms.AlarmMinutes.Count; i++) 274 | { 275 | 276 | 277 | if(design.Equals(alarms.AlarmDesign[i])) 278 | { 279 | if(hours == alarms.AlarmHour[i] && minutes == alarms.AlarmMinutes[i]) 280 | { 281 | if(alarms.AlarmSet[i] == 1) 282 | { 283 | Alarm.SetActive(true); 284 | Home.SetActive(false); 285 | Settings.SetActive(false); 286 | MyAlarm.SetActive(false); 287 | SetAlarmp.SetActive(false); 288 | Timep.SetActive(false); 289 | alarms.AlarmSet[i] = 0; 290 | indexCheck = i; 291 | } 292 | 293 | } 294 | } 295 | 296 | } 297 | /*if(design.Equals(alarms.AlarmDesign[i])) 298 | { 299 | if(hours == alarms.AlarmHour & minutes == alarms.AlarmMinutes) 300 | { 301 | 302 | Alarm.SetActive(true); 303 | Home.SetActive(false); 304 | Settings.SetActive(false); 305 | MyAlarm.SetActive(false); 306 | SetAlarmp.SetActive(false); 307 | Timep.SetActive(false); 308 | 309 | 310 | } 311 | }*/ 312 | } 313 | 314 | public void Dismissbt() 315 | { 316 | alarms.AlarmSet[indexCheck] = 0; 317 | //alarms.set = false; 318 | } 319 | 320 | public void Snooze() 321 | { 322 | snoozee = true; 323 | } 324 | 325 | public void Snooze15() 326 | { 327 | SD.snoozetimeduration = 900.0f; 328 | countdown = snoozetime = SD.snoozetimeduration; 329 | SD.checker15.SetActive(true); 330 | SD.checker30.SetActive(false); 331 | SD.checker45.SetActive(false); 332 | 333 | } 334 | 335 | public void Snooze30() 336 | { 337 | SD.snoozetimeduration = 1800.0f; 338 | countdown = snoozetime = SD.snoozetimeduration; 339 | SD.checker15.SetActive(false); 340 | SD.checker30.SetActive(true); 341 | SD.checker45.SetActive(false); 342 | 343 | } 344 | 345 | public void Snooze45() 346 | { 347 | SD.snoozetimeduration = 2700.0f; 348 | countdown = snoozetime = SD.snoozetimeduration; 349 | SD.checker15.SetActive(false); 350 | SD.checker30.SetActive(false); 351 | SD.checker45.SetActive(true); 352 | 353 | } 354 | 355 | IEnumerator SetAlarmText() 356 | { 357 | yield return new WaitForSeconds(5); 358 | alarmHr = hours; 359 | alarmMm = minutes; 360 | alarmDesign = design; 361 | 362 | 363 | } 364 | 365 | void SnoozeManager() 366 | { 367 | if (snoozee == true) 368 | { 369 | if (countdown > 0) 370 | { 371 | countdown -= Time.deltaTime; 372 | //alarms.set = false; 373 | alarms.AlarmSet[indexCheck] = 0; 374 | Alarm.SetActive(false); 375 | Home.SetActive(true); 376 | } 377 | 378 | if (countdown < 0) 379 | { 380 | Alarm.SetActive(true); 381 | Home.SetActive(false); 382 | Settings.SetActive(false); 383 | MyAlarm.SetActive(false); 384 | SetAlarmp.SetActive(false); 385 | Timep.SetActive(false); 386 | 387 | //alarms.set = true; 388 | alarms.AlarmSet[indexCheck] = 1; 389 | snoozee = false; 390 | countdown = snoozetime; 391 | } 392 | } 393 | } 394 | 395 | private void OnApplicationPause(bool pause) 396 | { 397 | if(pause == true) 398 | { 399 | CheckAlarm(); 400 | SnoozeManager(); 401 | } 402 | } 403 | 404 | } 405 | -------------------------------------------------------------------------------- /CameraDistance.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using Cinemachine; 3 | 4 | public class CameraDistance : MonoBehaviour 5 | { 6 | CinemachineVirtualCamera cam; 7 | 8 | void Start() 9 | { 10 | cam = GetComponent(); 11 | } 12 | 13 | void Camera(bool Zoom) 14 | { 15 | //Zoom by 100% 16 | if(Zoom) 17 | { 18 | CinemachineComponentBase componentBase = cam.GetCinemachineComponent(CinemachineCore.Stage.Body); 19 | if (componentBase is CinemachineFramingTransposer) 20 | { 21 | (componentBase as CinemachineFramingTransposer).m_CameraDistance = 10f; 22 | } 23 | } 24 | else 25 | { 26 | CinemachineComponentBase componentBase = cam.GetCinemachineComponent(CinemachineCore.Stage.Body); 27 | if (componentBase is CinemachineFramingTransposer) 28 | { 29 | (componentBase as CinemachineFramingTransposer).m_CameraDistance = 20f; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CameraShake.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Cinemachine; 5 | using UnityEngine.Rendering; 6 | 7 | public class CameraShake : MonoBehaviour 8 | { 9 | CinemachineVirtualCamera cam; 10 | public Volume vignette; 11 | public Animation pulsating; 12 | float shakeTimer; 13 | void Start() 14 | { 15 | cam = GetComponent(); 16 | } 17 | 18 | 19 | public void IntCS(float intensity, float timer) 20 | { 21 | CinemachineBasicMultiChannelPerlin CBMP = 22 | cam.GetCinemachineComponent(); 23 | CBMP.m_AmplitudeGain = intensity; 24 | shakeTimer = timer; 25 | } 26 | 27 | public void VignetteActivation(bool trigger) 28 | { 29 | if(trigger) 30 | { 31 | vignette.enabled = true; 32 | pulsating.Play(); 33 | } 34 | else 35 | { 36 | vignette.enabled = false; 37 | pulsating.Stop(); 38 | } 39 | } 40 | 41 | public void Zoom(bool trigger) 42 | { 43 | if(trigger) 44 | { 45 | cam.m_Lens.OrthographicSize = 17.5f; 46 | } 47 | else 48 | { 49 | cam.m_Lens.OrthographicSize = 14f; 50 | } 51 | } 52 | 53 | private void Update() 54 | { 55 | if(shakeTimer > 0) 56 | { 57 | shakeTimer -= Time.deltaTime; 58 | } 59 | else if (shakeTimer <= 0) 60 | { 61 | CinemachineBasicMultiChannelPerlin CBMP = 62 | cam.GetCinemachineComponent(); 63 | CBMP.m_AmplitudeGain = 0; 64 | this.transform.localRotation = Quaternion.Euler(0, 0, 0); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /CoinManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.SocialPlatforms.Impl; 5 | using UnityEngine.UI; 6 | 7 | public class CoinManager : MonoBehaviour 8 | { 9 | public static CoinManager instance; 10 | private Text coinText; 11 | public int coin; 12 | void Awake() 13 | { 14 | coinText = GameObject.Find("CoinText").GetComponent(); 15 | MakeSingleton(); 16 | } 17 | // Start is called before the first frame update 18 | void Start() 19 | { 20 | coin = PlayerPrefs.GetInt("coin"); 21 | coinText.text = coin.ToString(); 22 | } 23 | 24 | // Update is called once per frame 25 | void Update() 26 | { 27 | if (coinText == null) 28 | { 29 | coinText = GameObject.Find("CoinText").GetComponent(); 30 | coinText.text = coin.ToString(); 31 | } 32 | } 33 | public void AddCoin(int amount) 34 | { 35 | coin += amount; 36 | coinText.text = coin.ToString(); 37 | PlayerPrefs.SetInt("coin", coin); 38 | } 39 | 40 | public bool UseCoin(int amount) 41 | { 42 | bool success = false; 43 | if(amount <= coin) 44 | { 45 | coin -= amount; 46 | success = true; 47 | } 48 | coinText.text = coin.ToString(); 49 | PlayerPrefs.SetInt("coin", coin); 50 | return success; 51 | } 52 | void MakeSingleton() 53 | { 54 | if (instance != null) 55 | Destroy(gameObject); 56 | else 57 | { 58 | instance = this; 59 | DontDestroyOnLoad(gameObject); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /DamgeToPlayer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class DamgeToPlayer : MonoBehaviour 6 | { 7 | public float DamagePoint = 5; 8 | 9 | public health life; 10 | // Start is called before the first frame update 11 | void Start() 12 | { 13 | life = GameObject.FindGameObjectWithTag("Player").GetComponent(); 14 | } 15 | 16 | // Update is called once per frame 17 | void Update() 18 | { 19 | 20 | } 21 | 22 | /*private void OnCollisionEnter(Collision collision) 23 | { 24 | if(collision.gameObject.CompareTag("Player")) 25 | { 26 | life.healthAmount -= DamagePoint; 27 | } 28 | } */ 29 | 30 | private void OnTriggerEnter(Collider other) 31 | { 32 | if (other.gameObject.CompareTag("Player")) 33 | { 34 | life.TakeDamage(DamagePoint); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /DayAndNight.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class DayAndNight : MonoBehaviour 6 | { 7 | [Range(0, 1)] 8 | public float time; 9 | public float fullDayLength; 10 | public float startTime = 0.4f; 11 | public float timeRate; 12 | public Vector3 noon; 13 | 14 | [Header("Sun")] 15 | public Light sun; 16 | public Gradient sunColor; 17 | public AnimationCurve sunIntensity; 18 | 19 | [Header("Moon")] 20 | public Light moon; 21 | public Gradient moonColor; 22 | public AnimationCurve moonIntensity; 23 | 24 | [Header("Other Seetings")] 25 | public AnimationCurve lightingIntensityMultiplier; 26 | public AnimationCurve reflectionIntensityMultiplier; 27 | 28 | [SerializeField] 29 | private GameObject clouds; 30 | [SerializeField] 31 | private GameObject lightShafts; 32 | 33 | [SerializeField] 34 | private Color dayColor; 35 | [SerializeField] 36 | private Color nightColor; 37 | 38 | //private float duration = 2.0f; 39 | 40 | // Start is called before the first frame update 41 | void Start() 42 | { 43 | timeRate = 1 / fullDayLength; 44 | time = startTime; 45 | RenderSettings.fog = true; 46 | 47 | StartCoroutine(UpdateCycle()); 48 | } 49 | 50 | IEnumerator UpdateCycle() 51 | { 52 | while (true) 53 | { 54 | yield return new WaitForSeconds(Time.deltaTime); 55 | 56 | time += timeRate * Time.deltaTime; 57 | 58 | if (time >= 1) 59 | time = 0; 60 | 61 | sun.transform.eulerAngles = (time - 0.25f) * noon * 4.0f; 62 | moon.transform.eulerAngles = (time - 0.75f) * noon * 4.0f; 63 | 64 | sun.intensity = sunIntensity.Evaluate(time); 65 | moon.intensity = moonIntensity.Evaluate(time); 66 | 67 | sun.color = sunColor.Evaluate(time); 68 | moon.color = moonColor.Evaluate(time); 69 | 70 | if (sun.intensity == 0 && sun.gameObject.activeInHierarchy) 71 | { 72 | sun.gameObject.SetActive(false); 73 | } 74 | else if (sun.intensity > 0 && !sun.gameObject.activeInHierarchy) 75 | { 76 | sun.gameObject.SetActive(true); 77 | } 78 | 79 | if (moon.intensity == 0 && moon.gameObject.activeInHierarchy) 80 | { 81 | moon.gameObject.SetActive(false); 82 | } 83 | else if (moon.intensity > 0 && !moon.gameObject.activeInHierarchy) 84 | { 85 | moon.gameObject.SetActive(true); 86 | } 87 | 88 | if (!moon.gameObject.activeSelf) 89 | { 90 | RenderSettings.fogColor = dayColor; 91 | clouds.SetActive(true); 92 | lightShafts.SetActive(true); 93 | } 94 | else 95 | { 96 | RenderSettings.fogColor = nightColor; 97 | clouds.SetActive(false); 98 | lightShafts.SetActive(false); 99 | } 100 | 101 | RenderSettings.ambientIntensity = lightingIntensityMultiplier.Evaluate(time); 102 | RenderSettings.reflectionIntensity = reflectionIntensityMultiplier.Evaluate(time); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /DeleteAlarm.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | using System; 6 | 7 | public class DeleteAlarm : MonoBehaviour 8 | { 9 | public AlarmManager AM; 10 | public int child; 11 | public int count; 12 | public Toggle toggle; 13 | public bool check; 14 | 15 | void Start() 16 | { 17 | 18 | toggle = transform.Find("Toggle").GetComponent(); 19 | 20 | 21 | 22 | 23 | 24 | } 25 | void FixedUpdate() 26 | { 27 | 28 | child = transform.GetSiblingIndex(); 29 | count = AM.alarms.AlarmName.Count; 30 | try 31 | { 32 | AM.alarms.AlarmSet[child] = PlayerPrefs.GetInt("AlarmSet" + child); 33 | if(AM.alarms.AlarmSet[child] == 1) 34 | { 35 | toggle.isOn = true; 36 | check = true; 37 | } 38 | if(AM.alarms.AlarmSet[child] == 0) 39 | { 40 | toggle.isOn = false; 41 | check = false; 42 | } 43 | 44 | } 45 | catch(ArgumentOutOfRangeException ar) 46 | { 47 | Debug.Log("main button"); 48 | } 49 | } 50 | 51 | public void Delete() 52 | { 53 | int delete = transform.GetSiblingIndex(); 54 | DeleteA(delete); 55 | 56 | AM.alarms.AlarmHour.Clear(); 57 | AM.alarms.AlarmMinutes.Clear(); 58 | AM.alarms.AlarmDesign.Clear(); 59 | AM.alarms.AlarmName.Clear(); 60 | AM.alarms.AlarmSet.Clear(); 61 | foreach (Transform child in AM.content.transform) 62 | { 63 | Destroy(child.gameObject); 64 | } 65 | AM.LoadAlarm(); 66 | 67 | } 68 | 69 | void DeleteA(int index) 70 | { 71 | 72 | 73 | 74 | 75 | 76 | 77 | for (int i = index; i < count-1; i++) 78 | { 79 | AM.alarms.AlarmName[i] = AM.alarms.AlarmName[i+1]; 80 | AM.alarms.AlarmDesign[i] = AM.alarms.AlarmDesign[i+1]; 81 | AM.alarms.AlarmHour[i] = AM.alarms.AlarmHour[i+1]; 82 | AM.alarms.AlarmMinutes[i] = AM.alarms.AlarmMinutes[i+1]; 83 | AM.alarms.AlarmSet[i] = AM.alarms.AlarmSet[i+1]; 84 | 85 | 86 | 87 | PlayerPrefs.SetString("AlarmNames" + i, AM.alarms.AlarmName[i+1]); 88 | PlayerPrefs.SetString("AlarmDesigns" + i, AM.alarms.AlarmDesign[i+1]); 89 | PlayerPrefs.SetInt("AlarmMinutes" + i, AM.alarms.AlarmMinutes[i+1]); 90 | PlayerPrefs.SetInt("AlarmHours" + i, AM.alarms.AlarmHour[i+1]); 91 | PlayerPrefs.SetInt("AlarmSet" + i, AM.alarms.AlarmSet[i+1]); 92 | 93 | 94 | } 95 | count = count-1; 96 | 97 | /*int setindex = count-1; 98 | 99 | AM.alarms.AlarmName.RemoveAt(setindex); 100 | AM.alarms.AlarmMinutes.RemoveAt(setindex); 101 | AM.alarms.AlarmDesign.RemoveAt(setindex); 102 | AM.alarms.AlarmHour.RemoveAt(setindex); 103 | AM.alarms.AlarmSet.RemoveAt(setindex); 104 | 105 | PlayerPrefs.DeleteKey("AlarmNames" + setindex); 106 | PlayerPrefs.DeleteKey("AlarmDesigns" + setindex); 107 | PlayerPrefs.DeleteKey("AlarmMinutes" + setindex); 108 | PlayerPrefs.DeleteKey("AlarmHours" + setindex); 109 | PlayerPrefs.DeleteKey("AlarmSet" + setindex);*/ 110 | 111 | PlayerPrefs.SetInt("CountAlarmName", count); 112 | 113 | 114 | 115 | 116 | Destroy(gameObject); 117 | 118 | } 119 | 120 | public void AlarmActive() 121 | { 122 | if(check == true) 123 | { 124 | AM.alarms.AlarmSet[child] = 0; 125 | toggle.isOn = false; 126 | PlayerPrefs.SetInt("AlarmSet" + child, AM.alarms.AlarmSet[child]); 127 | check = false; 128 | }else 129 | 130 | if(check == false) 131 | { 132 | AM.alarms.AlarmSet[child] = 1; 133 | toggle.isOn = true; 134 | PlayerPrefs.SetInt("AlarmSet" + child, AM.alarms.AlarmSet[child]); 135 | check = true; 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /EnemyAI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | using UnityEngine; 6 | using UnityEngine.AI; 7 | using UnityEngine.Rendering; 8 | using UnityEngine.UI; 9 | 10 | // Define an enum for boss types 11 | public enum EnemyType 12 | { 13 | None, 14 | Boss1, 15 | Boss2, 16 | Boss3, 17 | Boss4, 18 | Boss5, 19 | Boss6, 20 | Rat 21 | } 22 | 23 | public class EnemyAI : MonoBehaviour 24 | { 25 | 26 | public float attackDistance = 3f; 27 | public float movementSpeed = 4f; 28 | public float move; 29 | public float _health = 100; 30 | public float attackRate = 0.5f; 31 | [HideInInspector] 32 | public Transform player; 33 | [HideInInspector] 34 | public NavMeshAgent agent; 35 | [HideInInspector] 36 | public float nextAttackTime = 0; 37 | public Animator Enemy; 38 | public Slider slide; 39 | 40 | public EnemyType enemyType; 41 | 42 | // Start is called before the first frame update 43 | void Start() 44 | { 45 | player = GameMgr.instance.shooter.transform; 46 | agent = GetComponent(); 47 | agent.stoppingDistance = attackDistance; 48 | agent.speed = move = movementSpeed; 49 | } 50 | 51 | private void OnEnable() 52 | { 53 | OnReactivation(); 54 | GameMgr.OnLastshot += HandleLastShot; 55 | GameMgr.OnGameOver += HandleGameOver; 56 | GoalArea.OnSendDamage += HandleReceiveDamage; 57 | GoalArea.OnSlowDownEnemy += HandleSlowDown; 58 | } 59 | 60 | private void OnDisable() 61 | { 62 | GameMgr.OnLastshot -= HandleLastShot; 63 | GameMgr.OnGameOver -= HandleGameOver; 64 | GoalArea.OnSendDamage -= HandleReceiveDamage; 65 | GoalArea.OnSlowDownEnemy -= HandleSlowDown; 66 | } 67 | public virtual void HandleLastShot(bool isLastShot) 68 | { 69 | // Use the isLastShot parameter to determine behavior 70 | if (isLastShot) InstantDestroy(); 71 | } 72 | 73 | public void OnReactivation() 74 | { 75 | if (slide != null) 76 | slide.value = _health; 77 | 78 | if (Health >= 100) return; 79 | 80 | Health = 100; 81 | 82 | if (enemyType != EnemyType.Rat) Enemy.SetBool("EnemyDead", false); 83 | 84 | movementSpeed = move; 85 | agent.enabled = true; 86 | } 87 | 88 | public virtual void HandleGameOver() => InstantDestroy(); 89 | public virtual void HandleReceiveDamage(float damage, bool redPause, bool hoopDamage) 90 | { 91 | if(redPause) 92 | { 93 | if (damage < 100 && hoopDamage) 94 | { 95 | switch (enemyType) 96 | { 97 | case EnemyType.Boss1: 98 | Health -= 10; 99 | break; 100 | case EnemyType.Boss2: 101 | Health -= 8; 102 | break; 103 | case EnemyType.Boss3: 104 | Health -= 6; 105 | break; 106 | case EnemyType.Boss4: 107 | Health -= 4; 108 | break; 109 | case EnemyType.Boss5: 110 | Health -= 2; 111 | break; 112 | case EnemyType.Boss6: 113 | Health -= 2; 114 | break; 115 | case EnemyType.Rat: 116 | break; 117 | default: 118 | Health -= damage; 119 | break; 120 | } 121 | } 122 | else 123 | Health -= damage; 124 | } 125 | else 126 | { 127 | Health -= damage; 128 | if (enemyType != EnemyType.Rat) Enemy.SetFloat("Damage", 1); 129 | DamageFeel(); 130 | } 131 | } 132 | 133 | public virtual void HandleSlowDown(float speed) 134 | { 135 | if (movementSpeed > 0) 136 | movementSpeed = movementSpeed - speed; 137 | 138 | CancelInvoke(nameof(ResetSpeed)); 139 | Invoke(nameof(ResetSpeed), 10f); 140 | } 141 | // Update is called once per frame 142 | public void Update() => AIMovement(); 143 | 144 | public virtual void AIMovement() 145 | { 146 | if (Health <= 0) return; 147 | 148 | agent.speed = movementSpeed; 149 | if (agent.remainingDistance - attackDistance < 0.01f) 150 | { 151 | if (Time.time > nextAttackTime) 152 | { 153 | nextAttackTime = Time.time + attackRate; 154 | } 155 | } 156 | 157 | if (movementSpeed == 0) return; 158 | 159 | //Move towardst he player 160 | agent.destination = player.position; 161 | transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.position.z)); 162 | } 163 | 164 | public float Health 165 | { 166 | get { return _health; } 167 | set 168 | { 169 | _health = value; 170 | if (_health <= 0) 171 | { 172 | 173 | movementSpeed = 0; 174 | agent.enabled = false; 175 | if (enemyType != EnemyType.Rat) Enemy.SetBool("EnemyDead", true); 176 | 177 | CancelInvoke(); 178 | Invoke(nameof(InstantDestroy), 10f); 179 | } 180 | 181 | if (slide != null) 182 | slide.value = _health; 183 | } 184 | } 185 | 186 | public void InstantDestroy() 187 | { 188 | movementSpeed = 0; 189 | agent.enabled = false; 190 | Health = 0; 191 | if (enemyType != EnemyType.Rat) Enemy.SetBool("EnemyDead", true); 192 | PoolSystem.instance.DeactivateToPool(name, gameObject); 193 | } 194 | 195 | private void ResetSpeed() => movementSpeed = 0.3f; 196 | 197 | void DamageFeel() 198 | { 199 | movementSpeed = 0; 200 | CancelInvoke(nameof(Recover)); 201 | Invoke(nameof(Recover), 5f); 202 | } 203 | void Recover() 204 | { 205 | if (enemyType != EnemyType.Rat) Enemy.SetFloat("Damage", -1); 206 | movementSpeed = move; 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /EnemyDamage.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class EnemyDamage : MonoBehaviour 6 | { 7 | public float maxDamagePoint = 20; 8 | public float minDamagePoint = 5; 9 | public GameObject OBJ; 10 | public GameObject spark; 11 | [HideInInspector] 12 | public health life; 13 | private void OnTriggerEnter(Collider other) 14 | { 15 | if (other.gameObject.CompareTag("enemy") || other.gameObject.CompareTag("Player")) 16 | { 17 | life = other.gameObject.GetComponent(); 18 | life.TakeDamage(Random.Range(minDamagePoint, maxDamagePoint)); 19 | } 20 | Instantiate(spark, this.transform.position, Quaternion.identity); 21 | Destroy(OBJ); 22 | Destroy(gameObject); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ItemDrop.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ItemDrop : MonoBehaviour 6 | { 7 | public health hp; 8 | public bool droped; 9 | public GameObject[] Dropable; 10 | // Start is called before the first frame update 11 | void Start() 12 | { 13 | 14 | } 15 | 16 | // Update is called once per frame 17 | void Update() 18 | { 19 | if(hp.dead && !droped) 20 | { 21 | Drop(); 22 | } 23 | } 24 | 25 | public void Drop() 26 | { 27 | 28 | for(int i = 0; i < Dropable.Length; i++) 29 | { 30 | GameObject item = Instantiate(Dropable[i], transform.position, Quaternion.identity, null); 31 | } 32 | 33 | droped = true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /NotificationManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using UnityEngine.UI; 4 | using TMPro; 5 | #if UNITY_ANDROID 6 | using Unity.Notifications.Android; 7 | using UnityEngine.Android; 8 | #elif UNITY_IOS 9 | using Unity.Notifications.iOS; 10 | #endif 11 | 12 | public class NotificationManager : MonoBehaviour 13 | { 14 | public Button SendNotifcationBtn; 15 | public TMP_InputField tittleInputField; 16 | public TMP_InputField messageInputField; 17 | public TMP_InputField timeInputField; 18 | private void Start() 19 | { 20 | #if UNITY_ANDROID 21 | if (!Permission.HasUserAuthorizedPermission("android.permission.POST_NOTIFICATIONS")) 22 | { 23 | Permission.RequestUserPermission("android.permission.POST_NOTIFICATIONS"); 24 | } 25 | 26 | var channel = new AndroidNotificationChannel() 27 | { 28 | Id = "channel_id", 29 | Name = "Default Channel", 30 | Importance = Importance.Default, 31 | Description = "Generic notifications", 32 | }; 33 | 34 | AndroidNotificationCenter.RegisterNotificationChannel(channel); 35 | #endif 36 | SendNotifcationBtn.onClick.AddListener(OnSendNotication); 37 | //SendNotification("Test Notification", "This is a test notification", 10); 38 | } 39 | 40 | public void OnSendNotication() 41 | { 42 | if (string.IsNullOrEmpty(timeInputField.text)) return; 43 | 44 | float time = float.Parse(timeInputField.text); 45 | string title = (string.IsNullOrEmpty(tittleInputField.text)) ? "Test Notification" : tittleInputField.text; 46 | string message = (string.IsNullOrEmpty(messageInputField.text)) ? $"Notifications in {time} minutes" : messageInputField.text; 47 | 48 | SendNotification(title, message, time); 49 | } 50 | 51 | public void SendNotification(string title, string message, float time) 52 | { 53 | #if UNITY_ANDROID 54 | var AndriodNotification = new AndroidNotification() 55 | { 56 | Title = title, 57 | Text = message, 58 | SmallIcon = "icon", 59 | LargeIcon = "logo", 60 | FireTime = DateTime.Now.AddMinutes(time), 61 | }; 62 | 63 | AndroidNotificationCenter.SendNotification(AndriodNotification, "channel_id"); 64 | 65 | #elif UNITY_IOS 66 | var timeTrigger = new iOSNotificationTimeIntervalTrigger() 67 | { 68 | TimeInterval = TimeSpan.FromMinutes(time), 69 | Repeats = false 70 | }; 71 | 72 | var notification = new iOSNotification() 73 | { 74 | Identifier = "_notification_01", 75 | Title = title, 76 | Body = message, 77 | Subtitle = "Test Subtitle", 78 | ShowInForeground = true, 79 | ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound), 80 | CategoryIdentifier = "category_id", 81 | ThreadIdentifier = "thread_id", 82 | Trigger = timeTrigger, 83 | }; 84 | 85 | iOSNotificationCenter.ScheduleNotification(notification); 86 | #endif 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Photon Unity Networking/NetwookPooling.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Photon.Pun; 5 | using Photon.Realtime; 6 | using System.IO; 7 | 8 | public class NetwookPooling :MonoBehaviourPun, IPunObservable 9 | { 10 | public static NetwookPooling Instance; 11 | 12 | PhotonView PV; 13 | 14 | [System.Serializable] 15 | public class Pool 16 | { 17 | public string tag; 18 | public string prefabName; 19 | public int size; 20 | } 21 | public List pools; 22 | 23 | public Dictionary> poolDictionary; 24 | 25 | 26 | 27 | // Start is called before the first frame update 28 | void Start() 29 | { 30 | PV = GetComponent(); 31 | 32 | 33 | if (PV.IsMine) 34 | { 35 | if (PhotonNetwork.IsMasterClient) 36 | { 37 | poolDictionary = new Dictionary>(); 38 | 39 | foreach (Pool pool in pools) 40 | { 41 | Queue objectpool = new Queue(); 42 | 43 | for (int i = 0; i < pool.size; i++) 44 | { 45 | GameObject obj = PhotonNetwork.InstantiateRoomObject(Path.Combine("PhotonPrefabs", pool.prefabName), transform.position, 46 | transform.rotation, 0); 47 | obj.SetActive(false); 48 | objectpool.Enqueue(obj); 49 | } 50 | 51 | poolDictionary.Add(pool.tag, objectpool); 52 | 53 | } 54 | 55 | } 56 | 57 | } 58 | 59 | } 60 | 61 | [PunRPC] 62 | public void CreatePools() 63 | { 64 | 65 | poolDictionary = new Dictionary>(); 66 | 67 | foreach (Pool pool in pools) 68 | { 69 | Queue objectpool = new Queue(); 70 | if (PhotonNetwork.IsMasterClient) 71 | { 72 | for (int i = 0; i < pool.size; i++) 73 | { 74 | GameObject obj = PhotonNetwork.InstantiateRoomObject(Path.Combine("PhotonPrefabs", pool.prefabName), transform.position, 75 | transform.rotation, 0); 76 | obj.SetActive(false); 77 | objectpool.Enqueue(obj); 78 | } 79 | 80 | 81 | 82 | } 83 | poolDictionary.Add(pool.tag, objectpool); 84 | } 85 | 86 | } 87 | public void InstantiateFromPool(string tag, Vector3 Position, Quaternion rotation, bool activate, Transform spawner, float force) 88 | { 89 | if (!poolDictionary.ContainsKey(tag)) 90 | { 91 | Debug.Log("Pool with tag" + tag + " doesn't excist."); 92 | return; 93 | } 94 | 95 | 96 | GameObject objectToSpawn = poolDictionary[tag].Dequeue(); 97 | 98 | objectToSpawn.SetActive(true); 99 | objectToSpawn.transform.position = Position; 100 | objectToSpawn.transform.rotation = rotation; 101 | if(activate) 102 | { 103 | Rigidbody2D rb = objectToSpawn.GetComponent(); 104 | rb.AddForce(spawner.up * force, ForceMode2D.Impulse); 105 | } 106 | 107 | //poolDictionary[tag].Enqueue(objectToSpawn); 108 | } 109 | 110 | public void DestroyToPool(string tag, GameObject objToDestroy) 111 | { 112 | if (!poolDictionary.ContainsKey(tag)) 113 | { 114 | Debug.Log("Pool with tag" + tag + " doesn't excist."); 115 | return; 116 | } 117 | 118 | 119 | poolDictionary[tag].Enqueue(objToDestroy); 120 | 121 | objToDestroy.SetActive(false); 122 | Rigidbody2D rb = objToDestroy.GetComponent(); 123 | rb.Sleep(); 124 | // objectToSpawn.transform.position = Position; 125 | // objectToSpawn.transform.rotation = rotation; 126 | 127 | } 128 | 129 | public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) 130 | { 131 | if(stream.IsWriting) 132 | { 133 | //stream.SendNext(poolDictionary); 134 | } 135 | else 136 | { 137 | // poolDictionary = (Dictionary>)stream.ReceiveNext(); 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /Photon Unity Networking/NeworkObservable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Photon.Pun; 5 | using Photon.Realtime; 6 | 7 | 8 | public class NeworkObservable : MonoBehaviourPun, IPunObservable 9 | { 10 | public NetworkWeaponManager NWM; 11 | public NetworkShooting[] NS; 12 | WeaponState state; 13 | 14 | private void Start() 15 | { 16 | NWM = GetComponent(); 17 | state = NWM.state; 18 | } 19 | public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) 20 | { 21 | if(stream.IsWriting) 22 | { 23 | stream.SendNext(NWM.state); 24 | } 25 | else 26 | { 27 | state = (WeaponState)stream.ReceiveNext(); 28 | NWM.state = state; 29 | } 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Photon Unity Networking/PhotonLobby.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Photon.Pun; 5 | using Photon.Realtime; 6 | using UnityEngine.UI; 7 | 8 | public class PhotonLobby : MonoBehaviourPunCallbacks 9 | { 10 | public static PhotonLobby lobby; 11 | 12 | public Text status; 13 | public GameObject battleButtom; 14 | public GameObject cancleButton; 15 | 16 | private void Awake() 17 | { 18 | lobby = this; 19 | } 20 | // Start is called before the first frame update 21 | void Start() 22 | { 23 | PhotonNetwork.ConnectUsingSettings();//connects to master photon server 24 | } 25 | 26 | public override void OnConnectedToMaster() 27 | { 28 | status.text = "Connected"; 29 | status.color = Color.green; 30 | 31 | 32 | PhotonNetwork.JoinLobby(); 33 | battleButtom.SetActive(true); 34 | } 35 | 36 | public override void OnJoinedLobby() 37 | { 38 | status.text = "Lobby joined"; 39 | PhotonNetwork.AutomaticallySyncScene = true; 40 | } 41 | 42 | public void OnBattleButtonClick() 43 | { 44 | PhotonNetwork.JoinRandomRoom(); 45 | status.text = "Searching for Room"; 46 | battleButtom.SetActive(false); 47 | cancleButton.SetActive(true); 48 | } 49 | 50 | public override void OnJoinRandomFailed(short returnCode, string message) 51 | { 52 | status.text = "Tried to join Room but failed"; 53 | CreateRoom(); 54 | 55 | } 56 | 57 | void CreateRoom() 58 | { 59 | status.text = "Room Created"; 60 | int randomRoomNumber = Random.Range(1, 10000); 61 | RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)MultiplayerSettings.multiplayerSettings.maxPlayers }; 62 | PhotonNetwork.CreateRoom("Room" + randomRoomNumber, roomOps); 63 | } 64 | 65 | public override void OnCreateRoomFailed(short returnCode, string message) 66 | { 67 | status.text = "Tried Creating Room but failed"; 68 | CreateRoom(); 69 | } 70 | public void OnCancledButtonClicked() 71 | { 72 | battleButtom.SetActive(true); 73 | cancleButton.SetActive(false); 74 | PhotonNetwork.LeaveRoom(); 75 | 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Photon Unity Networking/PhotonLobbyCustomMatch.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Photon.Pun; 5 | using Photon.Realtime; 6 | using UnityEngine.UI; 7 | 8 | public class PhotonLobbyCustomMatch : MonoBehaviourPunCallbacks , ILobbyCallbacks 9 | { 10 | public static PhotonLobbyCustomMatch lobby; 11 | 12 | public Text status; 13 | public string roomName; 14 | public int roomSize; 15 | public GameObject roomLisingPrefab; 16 | public Transform roomsPanel; 17 | public GameObject offlinebt; 18 | public GameObject lobbypanel; 19 | 20 | public List roomListings; 21 | 22 | private void Awake() 23 | { 24 | lobby = this; 25 | } 26 | // Start is called before the first frame update 27 | void Start() 28 | { 29 | PhotonNetwork.ConnectUsingSettings();//connects to master photon server 30 | roomListings = new List(); 31 | } 32 | 33 | public override void OnConnectedToMaster() 34 | { 35 | status.text = "Connected"; 36 | status.color = Color.green; 37 | 38 | PhotonNetwork.AutomaticallySyncScene = true; 39 | 40 | offlinebt.SetActive(false); 41 | lobbypanel.SetActive(true); 42 | } 43 | 44 | public override void OnRoomListUpdate(List roomList) 45 | { 46 | base.OnRoomListUpdate(roomList); 47 | //RemoveRoomListings(); 48 | int tempIndex; 49 | foreach(RoomInfo room in roomList) 50 | { 51 | if(roomListings != null) 52 | { 53 | tempIndex = roomListings.FindIndex(ByName(room.Name)); 54 | } 55 | else 56 | { 57 | tempIndex = -1; 58 | } 59 | 60 | if(tempIndex != -1) 61 | { 62 | roomListings.RemoveAt(tempIndex); 63 | Destroy(roomsPanel.GetChild(tempIndex).gameObject); 64 | } 65 | else 66 | { 67 | roomListings.Add(room); 68 | ListRoom(room); 69 | } 70 | } 71 | } 72 | 73 | static System.Predicate ByName(string name) 74 | { 75 | return delegate (RoomInfo room) 76 | { 77 | return room.Name == name; 78 | }; 79 | } 80 | 81 | void RemoveRoomListings() 82 | { 83 | int i = 0; 84 | while(roomsPanel.childCount != 0) 85 | { 86 | Destroy(roomsPanel.GetChild(i).gameObject); 87 | i++; 88 | } 89 | } 90 | 91 | void ListRoom(RoomInfo room) 92 | { 93 | if(room.IsOpen && room.IsVisible) 94 | { 95 | GameObject tempListing = Instantiate(roomLisingPrefab, roomsPanel); 96 | RoomButton tempButton = tempListing.GetComponent(); 97 | tempButton.roomName = room.Name; 98 | tempButton.roomSize = room.MaxPlayers; 99 | tempButton.SetRoom(); 100 | } 101 | } 102 | 103 | 104 | 105 | 106 | public void CreateRoom() 107 | { 108 | status.text = "Room Created"; 109 | RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)roomSize}; 110 | PhotonNetwork.CreateRoom(roomName, roomOps); 111 | } 112 | 113 | public override void OnCreateRoomFailed(short returnCode, string message) 114 | { 115 | status.text = "Change Room Name"; 116 | } 117 | 118 | public void OnRoomNameChanged(string nameIn) 119 | { 120 | roomName = nameIn; 121 | } 122 | 123 | public void OnRoomSizeeChanged(string sizeIn) 124 | { 125 | roomSize = int.Parse(sizeIn); 126 | } 127 | 128 | public void JoinlobbyOnClick() 129 | { 130 | if(!PhotonNetwork.InLobby) 131 | { 132 | PhotonNetwork.JoinLobby(); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /PlayerManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | using UnityEngine; 6 | using UnityEngine.UI; 7 | 8 | public class PlayerManager : MonoBehaviour 9 | { 10 | [SerializeField] GameObject[] characters; 11 | private int playerIndex; 12 | [SerializeField] Color[] PlayerColors; 13 | [SerializeField] MeshRenderer playerMesh; 14 | [SerializeField] Material playerMat; 15 | 16 | [SerializeField] GameObject homeUI; 17 | [SerializeField] GameObject buyCharacterUI; 18 | [SerializeField] GameObject[] charactersPanel; 19 | [SerializeField] GameObject[] lockUI; 20 | [SerializeField] int[] characterPrice; 21 | [SerializeField] Text[] characterPriceText; 22 | // Start is called before the first frame update 23 | void Start() 24 | { 25 | if(PlayerPrefs.HasKey("PlayerIndex")) 26 | { 27 | playerIndex = PlayerPrefs.GetInt("PlayerIndex"); 28 | OnCharacterSelect(playerIndex); 29 | playerMesh.enabled = false; 30 | } 31 | else 32 | { 33 | playerMesh.enabled = true; 34 | playerMat.color = playerMesh.material.color; 35 | } 36 | 37 | for (int i = 0; i < characterPriceText.Length; i++) 38 | { 39 | characterPriceText[i].text = characterPrice[i].ToString(); 40 | } 41 | OnlockUI(); 42 | } 43 | 44 | void OnlockUI() 45 | { 46 | for(int i = 0; i < lockUI.Length; i++) 47 | { 48 | if(PlayerPrefs.HasKey("PlayerBought" + i)) 49 | { 50 | lockUI[i].SetActive(false); 51 | } 52 | } 53 | } 54 | 55 | public void BuyCharacter(int index) 56 | { 57 | if (!PlayerPrefs.HasKey("PlayerBought" + index)) 58 | { 59 | bool success = CoinManager.instance.UseCoin(characterPrice[index]); 60 | if (!success) 61 | return; 62 | PlayerPrefs.SetInt("PlayerBought" + index, 1); 63 | OnCharacterSelect(index); 64 | homeUI.SetActive(true); 65 | buyCharacterUI.SetActive(false); 66 | } 67 | OnlockUI(); 68 | } 69 | 70 | public void OnCharacterSelect(int index) 71 | { 72 | if (PlayerPrefs.HasKey("PlayerBought" + index)) 73 | { 74 | PlayerPrefs.SetInt("PlayerIndex", index); 75 | playerMesh.material.color = PlayerColors[index]; 76 | playerMat.color = PlayerColors[index]; 77 | playerMesh.enabled = false; 78 | for (int i = 0; i < characters.Length; i++) 79 | { 80 | if (i == index) 81 | characters[i].SetActive(true); 82 | else 83 | characters[i].SetActive(false); 84 | } 85 | } 86 | else 87 | { 88 | homeUI.SetActive(false); 89 | buyCharacterUI.SetActive(true); 90 | for (int i = 0; i < charactersPanel.Length; i++) 91 | { 92 | if (i == index) 93 | charactersPanel[i].SetActive(true); 94 | else 95 | charactersPanel[i].SetActive(false); 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /PoolSystem.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class PoolSystem : MonoBehaviour 6 | { 7 | public static PoolSystem instance; 8 | 9 | [System.Serializable] 10 | public class Pool 11 | { 12 | public string tag; 13 | public GameObject prefab; 14 | public int size; 15 | } 16 | 17 | public List pools; 18 | public Dictionary> poolDictionary; 19 | private Dictionary activeObjects = new Dictionary(); 20 | 21 | #region Singleton/Pool Init 22 | private void Awake() 23 | { 24 | if(instance == null) 25 | { 26 | instance = this; 27 | } 28 | 29 | poolDictionary = new Dictionary>(); 30 | 31 | foreach (Pool pool in pools) 32 | { 33 | Queue objectPool = new Queue(); 34 | for (int i = 0; i < pool.size; i++) 35 | { 36 | GameObject obj = Instantiate(pool.prefab, transform); 37 | obj.SetActive(false); 38 | objectPool.Enqueue(obj); 39 | } 40 | 41 | poolDictionary.Add(pool.tag, objectPool); 42 | } 43 | } 44 | #endregion 45 | 46 | public GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation) 47 | { 48 | if(!poolDictionary.ContainsKey(tag)) 49 | return null; 50 | 51 | // Check if there are any inactive objects in the pool 52 | if (poolDictionary[tag].Count == 0) 53 | return null; 54 | 55 | GameObject objectToSpawn = poolDictionary[tag].Dequeue(); 56 | 57 | 58 | // Add the object to the active objects dictionary 59 | activeObjects.Add(objectToSpawn, tag); 60 | 61 | // Enable the object and call the OnSpawn method 62 | objectToSpawn.SetActive(true); 63 | objectToSpawn.transform.position = position; 64 | objectToSpawn.transform.rotation = rotation; 65 | 66 | return objectToSpawn; 67 | } 68 | 69 | public void DeactivateToPool(string tag, GameObject objectToDeactivate) 70 | { 71 | if (!poolDictionary.ContainsKey(tag)) 72 | return; 73 | 74 | // Check if the object is active and in the active objects dictionary 75 | if (objectToDeactivate.activeSelf && activeObjects.ContainsKey(objectToDeactivate)) 76 | { 77 | 78 | // Deactivate the object, remove it from the active objects dictionary, and return it to the pool 79 | objectToDeactivate.SetActive(false); 80 | objectToDeactivate.transform.parent = transform; 81 | activeObjects.Remove(objectToDeactivate); 82 | poolDictionary[tag].Enqueue(objectToDeactivate); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /PowerUp.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class PowerUp : MonoBehaviour 6 | { 7 | private GameMgr gamemanagerscript; 8 | public AudioClip hitnetSound; 9 | private int RandomNum; 10 | 11 | public enum PowerupState 12 | { 13 | greenball, 14 | blueball, 15 | none 16 | } 17 | PowerupState state; 18 | // Start is called before the first frame update 19 | void Start() 20 | { 21 | gamemanagerscript = GameObject.Find("GameManager").GetComponent(); 22 | } 23 | 24 | // Update is called once per frame 25 | void Update() 26 | { 27 | RandomNum = Random.Range(1, 100); 28 | if(RandomNum >= 1 && RandomNum <= 10) 29 | { 30 | state = PowerupState.greenball; 31 | } 32 | if (RandomNum >= 11 && RandomNum <= 20) 33 | { 34 | state = PowerupState.blueball; 35 | } 36 | if (RandomNum >= 21 && RandomNum <= 100) 37 | { 38 | state = PowerupState.none; 39 | } 40 | 41 | 42 | if (state == PowerupState.greenball) 43 | { 44 | //Activate PowerUP 45 | Debug.Log("isGreenball true"); 46 | gamemanagerscript.isGreenball = true; 47 | gamemanagerscript.isBlueball = false; 48 | //gamemanagerscript.isRedball = false; 49 | 50 | } 51 | if (state == PowerupState.blueball) 52 | { 53 | //Activate PowerUP 54 | Debug.Log("isblueball true"); 55 | gamemanagerscript.isGreenball = false; 56 | gamemanagerscript.isBlueball = true; 57 | //gamemanagerscript.isRedball = false; 58 | 59 | } 60 | if (state == PowerupState.none) 61 | { 62 | //Activate PowerUP 63 | Debug.Log("none true"); 64 | gamemanagerscript.isGreenball = false; 65 | gamemanagerscript.isBlueball = false;; 66 | //gamemanagerscript.isRedball = false; 67 | 68 | } 69 | 70 | } 71 | 72 | /*void OnTriggerEnter(Collider other) 73 | { 74 | 75 | if (other.gameObject.tag == "BasketBall") 76 | { 77 | if(state == PowerupState.greenball) 78 | { 79 | //Activate PowerUP 80 | Debug.Log("isGreenball true"); 81 | gamemanagerscript.isGreenball = true; 82 | StartCoroutine(DeactivateBall()); 83 | 84 | //AudioSource.PlayClipAtPoint(hitnetSound, gameObject.transform.position); 85 | } 86 | if (state == PowerupState.blueball) 87 | { 88 | //Activate PowerUP 89 | Debug.Log("isblueball true"); 90 | gamemanagerscript.isBlueball = true; 91 | StartCoroutine(DeactivateBall()); 92 | 93 | //AudioSource.PlayClipAtPoint(hitnetSound, gameObject.transform.position); 94 | } 95 | if (state == PowerupState.pinkball) 96 | { 97 | //Activate PowerUP 98 | Debug.Log("ispinkball true"); 99 | gamemanagerscript.isPinkball = true; 100 | StartCoroutine(DeactivateBall()); 101 | 102 | //AudioSource.PlayClipAtPoint(hitnetSound, gameObject.transform.position); 103 | } 104 | 105 | 106 | 107 | 108 | } 109 | } 110 | 111 | private IEnumerator DeactivateBall() 112 | { 113 | //gamemanagerscript.isGreenball = false; 114 | yield return new WaitForSeconds(10); 115 | if (state == PowerupState.greenball) 116 | { 117 | gamemanagerscript.isGreenball = false; 118 | state = PowerupState.blueball; 119 | } 120 | else if (state == PowerupState.blueball) 121 | { 122 | gamemanagerscript.isBlueball = false; 123 | state = PowerupState.pinkball; 124 | } 125 | else 126 | { 127 | gamemanagerscript.isPinkball = false; 128 | state = PowerupState.greenball; 129 | } 130 | 131 | } */ 132 | } 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MyScripts 2 | all just references 3 | 4 | [HIRE ME] 5 | 6 | Hello, I'm Yima Philemon, a Unity 3D game developer, Flutter developer, level designer, c#, and dart programmer with over 7 years of expertise in mobile VR, Unity 3D, Photon multiplayer, and Flutter. I am passionate about joining your team and contributing to the success of your projects. 7 | 8 | Some Scripts I have worked on 9 | 10 | You can connect to me via: 11 | 12 | yimaphilemon56@gmail.com 13 | 14 | https://yimaphilemon.weebly.com 15 | 16 | +2349120925909 17 | 18 | https://www.linkedin.com/in/yima-philemon-b07b161b9 19 | -------------------------------------------------------------------------------- /RandomSpawnInACircle.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ItemDrop : MonoBehaviour 6 | { 7 | public Transform spawnpoint; 8 | public float radius = 23f; 9 | public GameObject player; 10 | 11 | void Start() 12 | { 13 | Instantiate(player, RandomSpawn(spawnpoint.position), spawnpoint.rotation); 14 | } 15 | 16 | Vector2 RandomSpawn(Vector2 spawnPoint) 17 | { 18 | Vector2 rpoc = Random.insideUnitCircle * radius; 19 | rpoc += spawnPoint; 20 | return rpoc; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /RatAI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class RatAI : EnemyAI 4 | { 5 | public override void HandleReceiveDamage(float damage, bool redPause, bool hoopDamage) 6 | { 7 | //if(!hoopDamage) PoolSystem.instance.DeactivateToPool(name, this.gameObject); 8 | } 9 | public override void HandleSlowDown(float speed) { } 10 | public override void AIMovement() 11 | { 12 | agent.speed = movementSpeed; 13 | if (agent.remainingDistance - attackDistance < 0.01f) 14 | { 15 | if (Time.time > nextAttackTime) 16 | { 17 | nextAttackTime = Time.time + attackRate; 18 | } 19 | } 20 | 21 | //Move towardst he player 22 | agent.destination = player.position; 23 | transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.position.z)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Rotator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Rotator : MonoBehaviour 6 | { 7 | public float speed = 100; 8 | public bool rotate = true; 9 | void FixedUpdate() 10 | { 11 | if (!rotate) 12 | return; 13 | 14 | transform.Rotate(new Vector3(0, speed * Time.deltaTime, 0)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SavedAlarm.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | public class SavedAlarm : MonoBehaviour 7 | { 8 | [Serializable] 9 | public class MyAlarms 10 | { 11 | public string AlarmName; 12 | public string AlarmDesign; 13 | public int AlarmHour; 14 | public int AlarmMinutes; 15 | 16 | } 17 | public MyAlarms alarms; 18 | 19 | // Start is called before the first frame update 20 | void Start() 21 | { 22 | 23 | } 24 | 25 | // Update is called once per frame 26 | void Update() 27 | { 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ScrollSelect.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.EventSystems; 3 | using UnityEngine.UI; 4 | using TMPro; 5 | using System.Collections; 6 | 7 | public class ScrollSelect : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerDownHandler, IPointerUpHandler 8 | { 9 | public ScrollRect scrollRect; 10 | private TMP_InputField inputField; 11 | 12 | private bool dragging = false; 13 | private bool clickStarted = false; 14 | 15 | private void Start() 16 | { 17 | inputField = GetComponent(); 18 | } 19 | 20 | public void OnBeginDrag(PointerEventData eventData) 21 | { 22 | dragging = true; 23 | ExecuteEvents.Execute(scrollRect.gameObject, eventData, ExecuteEvents.beginDragHandler); 24 | } 25 | 26 | public void OnDrag(PointerEventData eventData) 27 | { 28 | if (dragging) 29 | { 30 | ExecuteEvents.Execute(scrollRect.gameObject, eventData, ExecuteEvents.dragHandler); 31 | } 32 | } 33 | 34 | public void OnEndDrag(PointerEventData eventData) 35 | { 36 | dragging = false; 37 | ExecuteEvents.Execute(scrollRect.gameObject, eventData, ExecuteEvents.endDragHandler); 38 | } 39 | 40 | public void OnPointerDown(PointerEventData eventData) 41 | { 42 | clickStarted = true; 43 | //inputField.interactable = false; 44 | 45 | if (inputField == null) 46 | return; 47 | 48 | inputField.DeactivateInputField(true); 49 | ExecuteEvents.Execute(scrollRect.gameObject, eventData, ExecuteEvents.pointerDownHandler); 50 | } 51 | 52 | public void OnPointerUp(PointerEventData eventData) 53 | { 54 | if (clickStarted) 55 | { 56 | clickStarted = false; 57 | 58 | if (inputField == null) 59 | return; 60 | 61 | StartCoroutine(Delay()); 62 | 63 | EventSystem.current.SetSelectedGameObject(inputField.gameObject, null); 64 | } 65 | } 66 | 67 | IEnumerator Delay() 68 | { 69 | yield return new WaitForSeconds(0.8f); 70 | 71 | inputField.interactable = true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /UITest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class UITest : MonoBehaviour 6 | { 7 | public ScreenOrientation targetOrientation = ScreenOrientation.Portrait; 8 | public void ChangeScreenOrienation() 9 | { 10 | if (Screen.orientation == ScreenOrientation.Portrait) 11 | { 12 | Screen.orientation = ScreenOrientation.LandscapeLeft; 13 | } 14 | else 15 | { 16 | Screen.orientation = ScreenOrientation.Portrait; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WatchManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | using System; 6 | 7 | public class WatchManager : MonoBehaviour 8 | { 9 | 10 | [Serializable] 11 | public class count 12 | { 13 | public float Sec; 14 | public float Hr; 15 | public float Min; 16 | public Text TextSec; 17 | public Text TextHr; 18 | public Text TextMin; 19 | public GameObject Stopbt; 20 | public GameObject Resetbt; 21 | public GameObject play; 22 | public GameObject stop; 23 | public GameObject buttons; 24 | public GameObject playbt; 25 | 26 | 27 | } 28 | public count CD; 29 | 30 | public float countdownSec; 31 | public float countdownMin; 32 | public float countdownH; 33 | 34 | public float StopwatchSec; 35 | public float StopwatchMin; 36 | public float StopwatchH; 37 | 38 | public Text StopwatchSecText; 39 | public Text StopwatchMinText; 40 | 41 | public bool stopwatchchecker = false; 42 | public GameObject Stopbt; 43 | public GameObject Lapbt; 44 | public GameObject play; 45 | public GameObject stop; 46 | public Button Lap; 47 | 48 | public bool counterchecker = false; 49 | public GameObject TimerAlarm; 50 | public GameObject Timer; 51 | //public float timeElapseSec; 52 | //public float timeElapseMin; 53 | //public Text ElapeSec; 54 | //public Text ElapeMin; 55 | 56 | public GameObject lap; 57 | public GameObject content; 58 | 59 | int index = 0; 60 | public Text num; 61 | public AudioSource click; 62 | public AudioSource tick; 63 | public AudioSource Alert; 64 | 65 | 66 | private void Awake() 67 | { 68 | WatchChecker(); 69 | } 70 | 71 | 72 | // Start is called before the first frame update 73 | void Start() 74 | { 75 | 76 | } 77 | 78 | // Update is called once per frame 79 | void FixedUpdate() 80 | { 81 | 82 | Stopwatch(); 83 | Counter(); 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | StopwatchSecText.text = StopwatchSec.ToString("00.00"); 92 | 93 | 94 | StopwatchMinText.text = StopwatchMin.ToString("00") + ":"; 95 | 96 | 97 | 98 | 99 | 100 | CD.TextHr.text = CD.Hr.ToString("00"); 101 | 102 | 103 | 104 | CD.TextMin.text = CD.Min.ToString("00"); 105 | 106 | 107 | 108 | CD.TextSec.text = CD.Sec.ToString("00"); 109 | 110 | 111 | 112 | 113 | if(counterchecker == true) 114 | { 115 | CD.Sec = countdownSec; 116 | CD.Min = countdownMin; 117 | CD.Hr = countdownH; 118 | 119 | } 120 | 121 | if(CD.Hr==0 && CD.Min==0 && CD.Sec==0) 122 | { 123 | CD.playbt.SetActive(false); 124 | CD.Stopbt.SetActive(false); 125 | CD.Resetbt.SetActive(false); 126 | } 127 | else 128 | { 129 | CD.playbt.SetActive(true); 130 | CD.Stopbt.SetActive(true); 131 | CD.Resetbt.SetActive(true); 132 | } 133 | 134 | if(counterchecker == true && countdownH <= 0 && countdownMin <= 0 && countdownSec <= 0) 135 | { 136 | TimerAlarm.SetActive(true); 137 | //Timer.SetActive(false); 138 | Alert.Play(); 139 | CD.buttons.SetActive(false); 140 | CD.Hr = 0; 141 | CD.Min = 0; 142 | CD.Sec = 0; 143 | 144 | counterchecker = false; 145 | 146 | 147 | /* (timeElapseSec >= 0) 148 | { 149 | timeElapseSec+=Time.deltaTime; 150 | 151 | } 152 | 153 | 154 | if(timeElapseSec >= 59) 155 | { 156 | timeElapseMin+=1f; 157 | timeElapseSec=0f; 158 | } */ 159 | 160 | 161 | 162 | } 163 | 164 | /* ElapeSec.text = timeElapseSec.ToString("00"); 165 | 166 | 167 | if (timeElapseMin < 10) { 168 | ElapeMin.text = "0" + timeElapseMin.ToString("0"); 169 | } 170 | 171 | else if (timeElapseMin > 9) 172 | { 173 | ElapeMin.text = timeElapseMin.ToString("0"); 174 | }*/ 175 | 176 | num.text = StopwatchMin.ToString("00") + ":" + StopwatchSec.ToString("00.00"); 177 | } 178 | 179 | public void StartStopWatch() 180 | { 181 | if(stopwatchchecker == false) 182 | { 183 | stopwatchchecker = true; 184 | stop.SetActive(false); 185 | play.SetActive(true); 186 | Lap.interactable = true; 187 | click.Play(); 188 | //Stopbt.SetActive(false); 189 | //Lapbt.SetActive(true); 190 | } 191 | 192 | 193 | } 194 | 195 | public void StopStopwatch() 196 | { 197 | if (stopwatchchecker == true) 198 | { 199 | stopwatchchecker = false; 200 | stop.SetActive(true); 201 | play.SetActive(false); 202 | Lap.interactable = false; 203 | click.Play(); 204 | //Stopbt.SetActive(true); 205 | //Lapbt.SetActive(false); 206 | } 207 | } 208 | 209 | public void StopWatchReset() 210 | { 211 | StopwatchH = 00.00F; 212 | StopwatchSec = 00.00F; 213 | StopwatchMin = 00.00F; 214 | stopwatchchecker = false; 215 | //Stopbt.SetActive(false); 216 | stop.SetActive(false); 217 | play.SetActive(false); 218 | Lap.interactable = false; 219 | click.Play(); 220 | foreach (Transform child in content.transform) 221 | { 222 | Destroy(child.gameObject); 223 | } 224 | index = 0; 225 | } 226 | 227 | public void AddHr() 228 | { 229 | CD.Hr++; 230 | tick.Play(); 231 | if (CD.Hr > 99) 232 | { 233 | CD.Hr = 00; 234 | } 235 | 236 | } 237 | 238 | public void SubHr() 239 | { 240 | CD.Hr--; 241 | tick.Play(); 242 | 243 | if (CD.Hr < 00) 244 | { 245 | CD.Hr = 99; 246 | } 247 | 248 | } 249 | 250 | public void AddMin() 251 | { 252 | CD.Min++; 253 | tick.Play(); 254 | if (CD.Min > 59) 255 | { 256 | CD.Min = 00; 257 | } 258 | 259 | } 260 | 261 | public void SubMin() 262 | { 263 | CD.Min--; 264 | tick.Play(); 265 | 266 | if (CD.Min < 00) 267 | { 268 | CD.Min = 59; 269 | } 270 | 271 | } 272 | 273 | public void AddSec() 274 | { 275 | CD.Sec++; 276 | tick.Play(); 277 | if (CD.Sec > 59) 278 | { 279 | CD.Sec = 00; 280 | } 281 | 282 | } 283 | 284 | public void SubSec() 285 | { 286 | CD.Sec--; 287 | tick.Play(); 288 | 289 | if(CD.Sec < 00) 290 | { 291 | CD.Sec = 59; 292 | } 293 | 294 | } 295 | 296 | public void StartCounter() 297 | { 298 | if(counterchecker == false) 299 | { 300 | counterchecker = true; 301 | CD.play.SetActive(true); 302 | CD.stop.SetActive(false); 303 | CD.buttons.SetActive(false); 304 | CD.Stopbt.SetActive(true); 305 | countdownH = CD.Hr; 306 | countdownMin = CD.Min; 307 | countdownSec = CD.Sec; 308 | click.Play(); 309 | //Alert.Play(); 310 | } 311 | 312 | 313 | 314 | 315 | 316 | } 317 | 318 | public void StopCounter() 319 | { 320 | if (counterchecker == true) 321 | { 322 | counterchecker = false; 323 | CD.play.SetActive(false); 324 | CD.stop.SetActive(true); 325 | click.Play(); 326 | //Alert.Stop(); 327 | } 328 | } 329 | 330 | public void ResetCounter() 331 | { 332 | 333 | counterchecker = false; 334 | CD.buttons.SetActive(true); 335 | CD.Stopbt.SetActive(false); 336 | CD.play.SetActive(false); 337 | CD.stop.SetActive(false); 338 | CD.Hr = 0; 339 | CD.Min = 0; 340 | CD.Sec = 0; 341 | //timeElapseSec = 0; 342 | //timeElapseMin = 0; 343 | click.Play(); 344 | //Alert.Stop(); 345 | 346 | 347 | } 348 | 349 | public void WatchChecker() 350 | { 351 | float cs = countdownSec; 352 | float ch = countdownH; 353 | float cm = countdownMin; 354 | } 355 | 356 | public void AddLap() 357 | { 358 | if(stopwatchchecker == true) 359 | { 360 | var copy = Instantiate(lap); 361 | copy.transform.parent = content.transform; 362 | copy.transform.localPosition = Vector3.zero; 363 | 364 | copy.GetComponentInChildren().text = (index + 1).ToString(); 365 | 366 | index++; 367 | click.Play(); 368 | //copy.GameObject.Find("time").GetComponentInChildren().text= (index).ToString(); 369 | } 370 | 371 | 372 | } 373 | 374 | public void Stopwatch() 375 | { 376 | if (stopwatchchecker == true) 377 | { 378 | if (StopwatchSec < 60f) 379 | { 380 | StopwatchSec += Time.deltaTime; 381 | 382 | } 383 | 384 | if (StopwatchSec > 59f) 385 | { 386 | StopwatchMin += 1f; 387 | StopwatchSec = 0f; 388 | } 389 | 390 | if (StopwatchMin > 59f) 391 | { 392 | StopwatchH += 1f; 393 | StopwatchMin = 0f; 394 | } 395 | 396 | 397 | } 398 | } 399 | 400 | public void Counter() 401 | { 402 | if (counterchecker == true) 403 | { 404 | if (countdownSec >= 0) 405 | { 406 | countdownSec -= Time.deltaTime; 407 | 408 | } 409 | 410 | if (countdownMin > 0) 411 | { 412 | if (countdownSec <= 0) 413 | { 414 | countdownMin -= 1f; 415 | countdownSec = 59f; 416 | } 417 | 418 | 419 | } 420 | 421 | if (countdownH > 0) 422 | { 423 | if (countdownMin <= 0) 424 | { 425 | countdownH -= 1f; 426 | countdownMin = 59f; 427 | } 428 | 429 | 430 | } 431 | 432 | } 433 | } 434 | 435 | public void DissmissCountdown() 436 | { 437 | counterchecker = false; 438 | CD.buttons.SetActive(true); 439 | CD.Stopbt.SetActive(false); 440 | CD.play.SetActive(false); 441 | CD.stop.SetActive(false); 442 | CD.Hr = 0; 443 | CD.Min = 0; 444 | CD.Sec = 0; 445 | //timeElapseSec = 0; 446 | //timeElapseMin = 0; 447 | click.Play(); 448 | Alert.Stop(); 449 | TimerAlarm.SetActive(false); 450 | } 451 | 452 | private void OnApplicationPause(bool pause) 453 | { 454 | if (pause == true) 455 | { 456 | Stopwatch(); 457 | Counter(); 458 | } 459 | } 460 | } 461 | --------------------------------------------------------------------------------