private void Awake() { //Should be Sticks at index 0 scoreType = GameManager.Instance.GameData.SpawnablePrefabList[0].GetComponent <Spawnable>().objectType; //should be Dynamite at index 1 loseType = GameManager.Instance.GameData.SpawnablePrefabList[1].GetComponent <Spawnable>().objectType; }
private void OnCollisionEnter2D(Collision2D collision) { GameObject collidedGameObject = collision.gameObject; ObjectTypeSO type = collidedGameObject.GetComponent <Spawnable>().objectType; if (type == scoreType) { //Score(collidedGameObject); scoreEventSO.Raise(); Destroy(collidedGameObject); } else if (type == loseType) { //Lose(collidedGameObject); loseEventSO.Raise(); Destroy(collidedGameObject); } else { Debug.LogError("spawnable type not found"); } return; }
private void OnCollisionEnter2D(Collision2D collision) { ObjectTypeSO type = collision.gameObject.GetComponent <Spawnable>().objectType; Debug.Log(type.name); if (type == scoreType) { //Debug.Log("stick out of bounds"); StickOBEventSO.Raise(); } if (type == loseType) { //Debug.Log("dynamite out of bounds"); DynamiteOBEventSO.Raise(); } Destroy(collision.gameObject); }
void InitializeSpawnedObj(GameObject spawnedObj) { ObjectTypeSO type = spawnedObj.GetComponent <Spawnable>().objectType; if (type == GameManager.Instance.GameData.SpawnablePrefabList[0].GetComponent <Spawnable>().objectType) //stick { spawnedObj.GetComponent <SpriteRenderer>().sprite = StickSkin; } else if (type == GameManager.Instance.GameData.SpawnablePrefabList[1].GetComponent <Spawnable>().objectType) //dynamite { spawnedObj.GetComponent <SpriteRenderer>().sprite = DynamiteSkin; } float randomSpinForce = Random.Range(-2, 2); Rigidbody2D spawnedRB2D = spawnedObj.GetComponent <Rigidbody2D>(); spawnedRB2D.AddTorque(baseTorque * randomSpinForce); spawnedRB2D.gravityScale = GameManager.Instance.GameData.spawnableGravityScale; }