Quantcast
Channel: Answers for "Link gun dynamics!"
Viewing all articles
Browse latest Browse all 6

Answer by aldonaletto

$
0
0
Once you put the prefab in the scene, an instance of it is created. Everything in this prefab is cloned to create this instance, including the scripts and their variables (except those declared as **static** - they are **global**), so you can have different values assigned to variables located in different instances of the same prefab. **TEXT ADDED TO THE ANSWER** Welcome, left brainer! Let's help your right side:
1- When the script spawns the enemies, it creates separated instances of them too, so they will be as independent as if you created them in the editor - every object in the game is an indepenent instance, no matter how it was created.
2- You can cast a ray from your camera to the center of the screen, which in principle is the point you will be aiming to. The script below was adapted from: http://unity3d.com/support/documentation/ScriptReference/Camera.ViewportPointToRay.html It just draws a line from the character to the point the camera is aiming to. I shifted the line origin downside 0.5m, or just a red point would appear in the center of the screen. You must also click the Gizmo button on the tool bar (above the Scene/Game window), or the line will not be drawn in the Game view. Don't get excited with this red ray: it will not appear in the final game, so forget about using Debug.DrawLine to create a cheap laser aim! function Update() { var ray : Ray = Camera.main.ViewportPointToRay (Vector3(0.5,0.5,0)); // Do a raycast var hit : RaycastHit; if (Physics.Raycast (ray, hit)){ var gunPos:Vector3 = transform.position; gunPos.y -= 0.5; Debug.DrawLine(gunPos,hit.point,Color.red); } }

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>