My script does not work each time i enter Unity unless i add it to the object again. any solutions?
I there i am pretty new at unity and found this script online and made a few edits(Javascript, and i do not understand the math behind it): #pragma strict
function Update () {
var pos = Camera.main.WorldToScreenPoint(transform.position); //A variable for the position of the camera on the world
var dir = Input.mousePosition - pos; //the mouse position minus the camera ray
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; //a equation that will find the correct angle to set the rotation from object to mouse
transform.rotation = Quaternion.AngleAxis(angle, Vector3.down); //the change of the rotations Y axis
}
For more info on what i am doing:
I am redoing the unity space tutorial game but added this to my ship so it can turn and shoot the bolts out
this code works for the player every time i enter unity but if you saw the tutorial you would know there is the "Shot Spawn" under it.
Shot spawn turns with the player ship whenever i delete the script as a component and bring it in
Does anyone know what is wrong with it so whenever i open Unity it can just stay and work?!?!
EDIT: I found a solution where i just make the code look for the player and not the shot spawn, and i made the bullets come out of the player to make it work every time
Your answer
Follow this Question
Related Questions
space shooter tutorial issue "Ending the game" unity 2018.2 b 1 Answer
Survival Shooter Error CS0120 1 Answer
unable to open example project 0 Answers