Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 03, 2016 at 04:11 PM by yvyv1000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by yvyv1000 · Aug 03, 2016 at 03:10 PM · scripting problemvariablebooleanmethodcall

can't call script variable from another script

this question may be asked a few times but the answers don't solve my problem

so I have this script

 var Price = 1500;
 var Bought = false;
 var Player : GameObject;
 
 function Update () {
 
 }
 
 function OnTriggerEnter(col : Collider){
 if(col.tag == "Player"){
     if(Input.GetKey(KeyCode.F)){
         Player.GetComponent.<RaycastShooting>().GotGunTwo = true;
     }
 }
 
 }

the object that's going to be player will have a RaycastShooting script attached to it. but unity outputs this error

Assets/Yvalson Scripts/BuyWallWeapon.js(12,30): BCE0018: The name 'RaycastShooting' does not denote a valid type ('not found'). Did you mean 'System.Net.Cache.RequestCacheLevel'?

I did it earlier with another script and that worked well why isn't it working now

for refference here is the raycastshooting script that is called for

 var Damage = 10;
 var FireRate = 0.1F;
 var NextFire = 0.0F;
 var BulletRange = 200;
 var ClipAk = 30;
 var TotalBulletsAk = 90;
 var ClipUMP = 45;
 var TotalBulletsUMP = 135;
 var ReloadTime = 1;
 var Nifes = 3;
 var SpreadFactor : float = 0;
 var AimSpread : float = 0.01;
 var HipFireSpread : float = 0.01;
 var AimCamera : GameObject; 
 var BulletHole : GameObject;
 var Nife : GameObject;
 var NifeSpawn : GameObject;
 var IsReloading = false;
 var GunFireSound : AudioClip;
 var EmptyGunSound : AudioClip;
 var Gun : GameObject;
 var GunReloadSound : AudioClip;
 var AnimationPlayed = false;
 var MuzzleFlash : GameObject;
 var GunTwo : GameObject;
 var ActiveGun = 2;
 var GotGunTwo = false;
 
 function Start() {
 
     GunReloadAnimation = Gun.GetComponent.<Animator>();
 }
 
 function Update() {
 
     MuzzleFlash = gameObject.FindWithTag("MuzzleFlash");
     MuzzleFlash.GetComponent.<Renderer>().enabled = false;
     AimCamera.GetComponent.<Crosshair>().enabled = true;
     SpreadFactor = HipFireSpread;
 
     if(Input.GetButton("Fire2")){
         AimCamera.GetComponent.<Crosshair>().enabled = false;
         SpreadFactor = AimSpread;
 
     }
 
 if(ActiveGun == 1){
     if(Input.GetButton("Fire1") && Time.time > NextFire && ClipAk > 0){
 
         NextFire = Time.time + FireRate;
         GetComponent.<AudioSource>().clip = GunFireSound;
         GetComponent.<AudioSource>().time = 0.2f;
         GetComponent.<AudioSource>().Play();
         Rayshooting();
         ClipAk --;
 
     }
     else if(ClipAk == 0 && TotalBulletsAk != 0){
         GetComponent.<AudioSource>().time = 0.4f;
         GetComponent.<AudioSource>().clip = GunReloadSound;
         GetComponent.<AudioSource>().Play();
         ReloadAk();
 
     }
     else if(Input.GetButtonDown("Fire1") && ClipAk == 0 && TotalBulletsAk == 0){
         EmptySound();
 
     }
 
     if(Input.GetKey(KeyCode.R) && ClipAk < 30 && TotalBulletsAk != 0 && IsReloading == false) {
         GetComponent.<AudioSource>().time = 0.4f;
         GetComponent.<AudioSource>().clip = GunReloadSound;
         GetComponent.<AudioSource>().Play();
         ReloadAk();
 
     }
 }
 
 if(ActiveGun == 2){
     if(Input.GetButton("Fire1") && Time.time > NextFire && ClipUMP > 0){
 
         NextFire = Time.time + FireRate;
         GetComponent.<AudioSource>().clip = GunFireSound;
         GetComponent.<AudioSource>().time = 0.2f;
         GetComponent.<AudioSource>().Play();
         Rayshooting();
         ClipUMP --;
 
     }
     else if(ClipUMP == 0 && TotalBulletsUMP != 0){
         GetComponent.<AudioSource>().time = 0.4f;
         GetComponent.<AudioSource>().clip = GunReloadSound;
         GetComponent.<AudioSource>().Play();
         ReloadUMP();
 
     }
     else if(Input.GetButtonDown("Fire1") && ClipUMP == 0 && TotalBulletsUMP == 0){
         EmptySound();
 
     }
 
     if(Input.GetKey(KeyCode.R) && ClipUMP < 45 && TotalBulletsUMP != 0 && IsReloading == false) {
         GetComponent.<AudioSource>().time = 0.4f;
         GetComponent.<AudioSource>().clip = GunReloadSound;
         GetComponent.<AudioSource>().Play();
         ReloadUMP();
 
     }
 }
 
     if(Input.GetKeyDown(KeyCode.E) && Nifes > 0){
         Instantiate(Nife, NifeSpawn.transform.position, NifeSpawn.transform.rotation);
         Nifes --;
     }
 
 
 if(GotGunTwo == true){
     if(Input.GetKeyDown(KeyCode.Alpha1)){
         WeaponSwitch();
     }
 }
 
 }
 
 function Rayshooting() {
     {
         MuzzleFlash.GetComponent.<Renderer>().enabled = true;
         yield WaitForSeconds(0.02);
         MuzzleFlash.GetComponent.<Renderer>().enabled = false;
     }
     var direction : Vector3 = transform.forward;
 
     direction.x += Random.Range(-SpreadFactor, SpreadFactor);
     direction.y += Random.Range(-SpreadFactor, SpreadFactor);
     direction.z += Random.Range(-SpreadFactor, SpreadFactor);
 
     Debug.DrawRay(transform.position,direction * BulletRange);
     var hit : RaycastHit;
 
         bHit = Physics.Raycast(transform.position,direction,hit,BulletRange);
         if (bHit && hit.transform.gameObject.tag == "Enemy"){
             hit.transform.SendMessage("DamageTaken", Damage, SendMessageOptions.DontRequireReceiver);
         }
         else if (bHit && hit.transform.gameObject.tag == "Buildings" || "Buildings2"){
             var CloneHole = Instantiate(BulletHole, hit.point, Quaternion.LookRotation(hit.normal));
             Destroy(CloneHole, 5);
         }
 
 } 
 
 function ReloadAk() {
 
     if(ActiveGun == 1){
         Gun.GetComponent.<Animation>().Play("Reload");
     }
     else if(ActiveGun == 2){
         GunTwo.GetComponent.<Animation>().Play("Reload UMP");
     }
     yield WaitForSeconds(ReloadTime);
 
     if(ClipAk == 0 && TotalBulletsAk >= 30){
         ClipAk = 30;
         TotalBulletsAk -= 30;
     }
     if(ClipAk == 0 && TotalBulletsAk << 30){
         ClipAk = TotalBulletsAk;
         TotalBulletsAk = TotalBulletsAk - TotalBulletsAk;
     }
     if(ClipAk != 0 && TotalBulletsAk >= 30 - ClipAk){
         TotalBulletsAk = TotalBulletsAk - (30 - ClipAk);
         ClipAk = 30;
     }
     else if(ClipAk != 0 && TotalBulletsAk << 30 - ClipAk){
         ClipAk = ClipAk + TotalBulletsAk;
         TotalBulletsAk = 0;
     }
 }
 
 function ReloadUMP() {
 
     if(ActiveGun == 1){
         Gun.GetComponent.<Animation>().Play("Reload");
     }
     else if(ActiveGun == 2){
         GunTwo.GetComponent.<Animation>().Play("Reload UMP");
     }
     yield WaitForSeconds(ReloadTime);
 
     if(ClipUMP == 0 && TotalBulletsUMP >= 45){
         ClipUMP = 45;
         TotalBulletsUMP -= 45;
     }
     if(ClipUMP == 0 && TotalBulletsUMP << 45){
         ClipUMP = TotalBulletsUMP;
         TotalBulletsUMP = TotalBulletsUMP - TotalBulletsUMP;
     }
     if(ClipUMP != 0 && TotalBulletsUMP >= 45 - ClipUMP){
         TotalBulletsUMP = TotalBulletsUMP - (45 - ClipUMP);
         ClipUMP = 45;
     }
     else if(ClipUMP != 0 && TotalBulletsUMP << 45 - ClipUMP){
         ClipUMP = ClipUMP + TotalBulletsUMP;
         TotalBulletsUMP = 0;
     }
 }
 
 function EmptySound(){
         GetComponent.<AudioSource>().time = 0.0f;
         GetComponent.<AudioSource>().volume = 1;
         GetComponent.<AudioSource>().clip = EmptyGunSound;
         GetComponent.<AudioSource>().Play();
 }
 
 function WeaponSwitch(){
         if(Gun.active == true){
             Gun.GetComponent.<Animation>().Play("WeaponOut");
             yield WaitForSeconds(0.5);
             Gun.SetActive(false);
             GunTwo.SetActive(true);
             GunTwo.GetComponent.<Animation>().Play("WeaponIn");
             ActiveGun = 2;
         }
         else{
             GunTwo.GetComponent.<Animation>().Play("WeaponOut");
             yield WaitForSeconds(0.5);
             GunTwo.SetActive(false);
             Gun.SetActive(true);
             Gun.GetComponent.<Animation>().Play("WeaponIn");
             ActiveGun = 1;
         }
 }

as you can see in the raycastshooting script I used the same thing here

 var AimCamera : GameObject; 

     AimCamera.GetComponent.<Crosshair>().enabled = true;

this does not put any errors at all what's wrong?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Landern · Aug 03, 2016 at 03:12 PM

Since this is unityscript/javascript you need to be mindful of the file name that contains the "raycastshooting" code. In c# when you define a class it's explicitly, in your case it's using the file name to create the class. Make sure you're referencing the type exactly how it's spelt including the case of the characters. Behind the scenes Unity is compiling/building a class for you.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yvyv1000 · Aug 03, 2016 at 04:07 PM 0
Share

but I'm using the correct upper casing of letters

avatar image yvyv1000 · Aug 03, 2016 at 04:10 PM 0
Share

well just looked back and well there was a space between Raycast and Shooting in the name so I just removed the space and it worked ill mark the answer as accepted

avatar image Landern yvyv1000 · Aug 03, 2016 at 05:06 PM 0
Share

glad you have it working

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Access a variable from another script in update function 1 Answer

Toggle Boolean Function 2 Answers

How to change the rate of decrease in a variable in the update function 1 Answer

Script not responding to public variable change 1 Answer

Accessing variable from a method in another script and gameObject 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges