void OnCollisionEnter(Collision collision) { if (collision.collider.tag == "Enemy") { //PathThroughObjects path = collision.gameObject.GetComponent<PathThroughObjects>(); //path.speed *= slowPercentage; //restoreSpeedObject = new RestoreSpeed(); // Instantiate< RestoreSpeed>() as RestoreSpeed; restoreSpeedObject = collision.gameObject.GetComponent <RestoreSpeed>(); GameObject slowDownEffect = null; if (restoreSpeedObject == null) { restoreSpeedObject = collision.gameObject.AddComponent <RestoreSpeed>(); slowDownEffect = Instantiate(Resources.Load("SlowDownEffect"), collision.gameObject.transform.position, Quaternion.identity) as GameObject; slowDownEffect.transform.parent = collision.gameObject.transform; } restoreSpeedObject.Begin(slowPercentage, slowTime, slowDownEffect); Destroy(gameObject); } }
void OnCollisionEnter(Collision collision) { if (collision.collider.tag == "Enemy") { if (!collision.collider.GetComponentInChildren <RestoreSpeed>()) { PathThroughObjcets scriptInstance = collision.collider.GetComponent <PathThroughObjcets>(); GameObject restoreSpeedInstance = Instantiate(restoreSpeedObject, collision.collider.transform.position, Quaternion.identity) as GameObject; restoreSpeedInstance.transform.parent = collision.collider.transform; RestoreSpeed scriptInstance2 = restoreSpeedInstance.GetComponent <RestoreSpeed>(); scriptInstance2.time = slowTime; scriptInstance2.originalSpeed = scriptInstance.speed; scriptInstance.speed *= slowPercentage; } } }
void OnCollisionEnter(Collision col) { if (col.collider.tag == "Enemy") { col.collider.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); if (col.collider.GetComponentInChildren <RestoreSpeed>() == null) { PathTroughObject scriptInstance = col.collider.GetComponent <PathTroughObject>(); GameObject restoreSpeedIntsnce = Instantiate(restoreSoeedObhect, col.collider.transform.position, Quaternion.identity) as GameObject; restoreSpeedIntsnce.transform.parent = col.collider.transform; RestoreSpeed scriptInstance2 = restoreSpeedIntsnce.GetComponent <RestoreSpeed>(); scriptInstance2.time = slowSpeed; scriptInstance2.originalSpeed = scriptInstance.speed; scriptInstance.speed *= slowPercentage; } Destroy(gameObject); } }