Quantcast
Channel: Questions in topic: "tree"
Viewing all articles
Browse latest Browse all 513

Script work in Unity but not in Game (Builded)

$
0
0
Hello everyone so i'm honestly really lost i've searched a solution but it seems to be uncommon, so there is all informations (It's an FPS game): I have scripts to cut Trees, when you hit the tree 5 times (click 5 times) with your leftclick the tree disapear after 7seconds and drops 3 logs and 3 coconuts , there is one script on the Tree where I need to put the prefab of the log and coconut, and there is a script called TreeRayCast (attached to the main camera) and this script defines the range of the left click (The max distance between your axe and the tree to cut it). The two scripts are Javascript. It's working like a charm ... but only in unity ! When I test the game (on unity) it's working perfectly but when I build and run the game and i hit a tree 5 times nothing happens ... Same problem if I close Unity ! **Example:** All is working in Unity, I save my scene + project and I close unity, the next day I open Unity I press play and it's not working -> Nothing happens after I hit the tree 5 times so I delete the TreeRayCast from the project and i re-add it and ... It works !(but only in unity once again) So my conclusion: Problem coming from the TreeRayCast, there is the script; Someone got an idea to fix that ? the tag of trees are Tree like in the script and I don't have any errors on console ! #pragma strict var rayLength = 10; private var treeScript : TreeController; private var playerAnim : PlayerControl; function Update() { var hit : RaycastHit; var fwd = transform.TransformDirection(Vector3.forward); if(Physics.Raycast(transform.position, fwd, hit, rayLength)) { if(hit.collider.gameObject.tag == "Tree") { treeScript = GameObject.Find(hit.collider.gameObject.name).GetComponent(TreeController); playerAnim = GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerControl); if(Input.GetButtonDown("Fire1") && playerAnim.canSwing == true) { treeScript.treeHealth -= 1; } } } }

Viewing all articles
Browse latest Browse all 513

Trending Articles



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