Variable call don't work

Hello,

I’m trying to shoot a bullet from the current player position to my cursor clic.
I instantiate a bullet at the player position in a script on the player and put an other script on the bullets with an “AddForce”. I call a Vector3 variable " direction" in the player script and put in the bullet script for the direction of my bullet.
The direction work in my player script but is always egal to (0,0,0) in my bullet script :

Player Script :

Bullet Script :


Direction of the bullet in the bullet scirpt :

3552577--285792--upload_2018-7-3_22-43-59.png

Direction of the bulle in player script

3552577--285793--upload_2018-7-3_22-44-19.png

I dont notice a problem in the script, i’m on this for days and i dont understant.
Thanks !

Please don’t post pictures of code. Just paste the code, using the “Code:” button right there in the editing toolbar.

I don’t think the problem is in the code you’ve shown us. You can delete the spurious FindObjectOfType line in your bullet script; you’re not using the result anyway. You must have hooked up the player field in the inspector or some such. I suspect that this doesn’t refer to the object you think it does — perhaps it refers to a prefab instead of the live instance, or something like that.

A good way to pin that down is, use the second parameter of Debug.Log. This is a game object that you want Unity to highlight when you select that message in the Console. So change your Debug.Log to:

Debug.Log("PPP" + bulletInstantiate.direction, bulletInstantiate.gameObject);

And now when you click that PPP line in the editor, you can see what bulletInstantiate it’s looking at.

Another possibility is that you have two PlayerComponent components on your player object. That would certainly confuse things.