|
Post by fahrettin on Apr 21, 2014 10:04:51 GMT
Made a new thread but if its wrong sorry.
I asked you this question and always search about it. I found a project with this code
private var hit: RaycastHit;
function Start () {
}
function Update () { var ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Input.GetMouseButtonDown(0)) { if ( Physics.Raycast ( ray, hit, Mathf.Infinity)) { if(hit.collider.tag == "a1") { Destroy (gameObject); } } }
} It works with separate objects. I need to change tag for all the objects and its not really useful. If use prefab i destroy all the objects simultaneously.
|
|
DarkTonic Dev
Administrator
Posts: 4,229
Posts: 4,229
Member is Online
|
Post by DarkTonic Dev on Apr 21, 2014 16:12:34 GMT
What is your question? Are you wanting to know how to adapt that code so that it destroys a Killable and activates the World Variable Modifiers for it?
|
|
|
Post by fahrettin on Apr 21, 2014 16:42:22 GMT
Yes i want to know how to adapt that code. And i am starter but this code destroy objects completely like deleting from game. No score etc. I am testing on your triggered spawner scene but without player object.
|
|
|
Post by darktonic on Apr 21, 2014 18:50:37 GMT
Yes i want to know how to adapt that code. And i am starter but this code destroy objects completely like deleting from game. No score etc. I am testing on your triggered spawner scene but without player object. Ok. Replace your Destroy line with this. var kill = gameObject.GetComponent<Killable>(); kill.DestroyKillable (); This is C#. I don't know UnityScript. Hopefully you can convert it without much trouble.
|
|
|
Post by fahrettin on Apr 21, 2014 19:10:24 GMT
Thanks for your help. You always answer my questions kindly
I converted script and simply tested your advice and it worked perfect (2.TriggeredSpawners) 
Tried on your other scene(1.TimedAndEliminationWaves) and i couldnt find solution on my own. Added script to enemy prefab. If i do that prefabs self-destruct. They dont need touch.
|
|
DarkTonic Dev
Administrator
Posts: 4,229
Posts: 4,229
Member is Online
|
Post by DarkTonic Dev on Apr 21, 2014 20:10:29 GMT
Excellent! Is there another question here?
|
|
|
Post by fahrettin on Apr 21, 2014 22:36:00 GMT
Yes its excellent but i cant use this script with spawners.
|
|
DarkTonic Dev
Administrator
Posts: 4,229
Posts: 4,229
Member is Online
|
Post by DarkTonic Dev on Apr 21, 2014 23:31:25 GMT
Which type of spawners? Triggered or Syncro?
|
|
|
Post by fahrettin on Apr 22, 2014 0:15:30 GMT
Which type of spawners? Triggered or Syncro? In scene 2.TriggeredSpawners you put prefabs directly to hierarchy. When i add my script to them one by one it works. In scene 1.TimedAndEliminationWaves you put Syncrospawners. If i add my script to spawners it doesnt work. Tried to put script to spawned prefabs (Enemy, Enemy2 etc.) they self-destruct. Every time i need to prepare my scene and objects like 2.TriggeredSpawners. They have very useful options but i cant use spawners. (English isnt my 1st language but i tried my best  )
|
|
DarkTonic Dev
Administrator
Posts: 4,229
Posts: 4,229
Member is Online
|
Post by DarkTonic Dev on Apr 22, 2014 0:43:27 GMT
In Scene 2.TriggeredSpawners, the first problem is that the enemies are in IgnoreRaycast layer, which cannot be hit by raycasts. Make a new layer "enemies" and make all the enemy prefabs use that layer.
Next, if you put this script on the enemy prefab, it will kill ALL of them when you hit one of them. That's not what you want. Instead, put this script onto the Player prefab. This fixed script works for me:
using UnityEngine; using System.Collections;
public class ClickToKill : MonoBehaviour { void Update() { var ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if(hit.collider == null) { return; } var kill = hit.collider.GetComponent<Killable>(); if (kill != null) { kill.DestroyKillable(); } } } } }
I will include this script in the next version. And this should let you use spawners.
|
|
|
Post by fahrettin on Apr 22, 2014 8:50:20 GMT
Tried your update and it works perfect. You helped to a noob with patience  Thanks
|
|
DarkTonic Dev
Administrator
Posts: 4,229
Posts: 4,229
Member is Online
|
Post by DarkTonic Dev on Apr 22, 2014 16:18:41 GMT
No problem! Actually the updated Core GameKit with this script is already live. I also added an option to inflict X damage on the Killable instead of Destroying it.
|
|
|
Post by fahrettin on Apr 22, 2014 21:43:05 GMT
No problem! Actually the updated Core GameKit with this script is already live. I also added an option to inflict X damage on the Killable instead of Destroying it. I have a project in my mind. At this moment i just tried script and its features. "inflict X damage" is super because i was thinking just destroying object 
|
|
DarkTonic Dev
Administrator
Posts: 4,229
Posts: 4,229
Member is Online
|
Post by DarkTonic Dev on Apr 22, 2014 22:10:13 GMT
Perfect!
|
|