Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Jan 19, 2014 at 12:46 AM by FPSworrior for the following reason:

I fixed it myself.

avatar image
0
Question by FPSworrior · Jan 12, 2014 at 10:59 PM · errorai

Why am I getting this error?

/Scripts/Soldier.cs(113,28): error CS1061: Type AI' does not contain a definition for suspition' and no extension method suspition' of type AI' could be found (are you missing a using directive or an assembly reference?) I am trying to make a script where if I enter the enemy trigger their suspition raises. In order to do this I have to access a variable from the AI script from my soldier script. Here are the scripts. /Scripts/Soldier.cs(113,28): error CS1061: Type AI' does not contain a definition for suspition' and no extension method suspition' of type AI' could be found (are you missing a using directive or an assembly reference?)

 My soldier script below.
  

 using UnityEngine;
 using System.Collections;
 
 public class Soldier : MonoBehaviour {
     private AI ai;
     public float suspitionSpeed;
     public float health;
     public float hitSpeed = 20.0f;
     public int score;
     public GUIText scoreText;
     public GUIText healthText;
     public GUIText dead;
     private bool canPickUpHealth;
     private bool isHit = false;
     private bool isShot = false;
     // Use this for initialization
     void Start () {
         SetHealthText();
         SetScoreText();
         dead.text = "";
         canPickUpHealth = false;
         score = 0;
         Time.timeScale = 1;
         ai = GetComponent<AI>();
     }
     
     // Update is called once per frame
     void Update () {
         if(health >= 100.0f)
         {
             health = 100.0f;
             SetHealthText();
         }
         if(health < 0.0f)
         {
             health = 0.0f;
             SetHealthText();
         }
         if(health <= 0.0f)
         {
             Time.timeScale = 0;
             dead.text = "YOU ARE DEAD";
             SetHealthText();
         }
         if(health == 100.0f)
         {
             canPickUpHealth = false;
         }
         else
         {
             canPickUpHealth = true;
         }
         if(isHit)
         {
             health -= Time.deltaTime * hitSpeed;
             health = Mathf.Round(health);
             SetHealthText();
         }
         else
         {
             isHit = false;
         }
 
         if(isShot)
         {
             hitSpeed = 25.0f;
             health -= Time.deltaTime * hitSpeed;
             health = Mathf.Round(health);
             SetHealthText();
         }
         else
         {
             isShot = false;
             hitSpeed = 20.0f;
         }
 
         if(Input.GetKeyDown (KeyCode.Space))
         {
             audio.Play();
         }
 
     }
 
     void OnTriggerEnter(Collider other)
     {
         if( other.gameObject.tag == "Health" && Input.GetKeyUp(KeyCode.E))
         {
               if(canPickUpHealth)
             {
               health = health + 15.0f;
               other.gameObject.SetActive(false);
               SetHealthText();
             }
         }
         if(other.gameObject.tag == "Enemy" && health > 0.0f)
         {
             isHit = true;
         }
         if(other.gameObject.tag == "Bullet" && health > 0.0f)
         {
             isShot = true;
             hitSpeed = 25.0f;
         }
 
         if(other.gameObject.tag == "PickUp")
         {
             other.gameObject.SetActive(false);
             score = score + 10;
             SetScoreText();
         }
         if(other.gameObject.tag == "Suspicion")
         {
             ai.suspition += Time.deltaTime * suspitionSpeed;
         }
     }
 
     void OnTriggerStay(Collider other)
     {
         //if(other.gameObject.tag == "Enemy")
         //{
         //    isHit = false;
         if( other.gameObject.tag == "Health" && Input.GetKeyUp(KeyCode.E))
         {
             if(canPickUpHealth)
             {
                 health = health + 15.0f;
                 other.gameObject.SetActive(false);
                 SetHealthText();
                 audio.Play();
             }
         }
     }
 
     void OnTriggerExit(Collider other)
     {
         if(other.gameObject.tag == "Enemy")
         {
             isHit = false;
         }
         if(other.gameObject.tag == "Bullet" && health > 0.0f)
         {
             isShot = false;
         }
     }
 
     void SetHealthText()
     {
         healthText.text = "Health: " + health.ToString();
         if(health <= 0.0f)
         {
             dead.text = "YOU ARE DEAD";
         }
     }
     void SetScoreText()
     {
         scoreText.text = "Score: " + score.ToString();
     }
     
 }


Here is my AI script below.

 using UnityEngine;
 using System.Collections;
 
 public class AI : MonoBehaviour {
 
     public float suspition;
     public int health = 100;
     public Transform target;
     public bool foundTarget = false;
     public int movespeed;
     public int rotateSpeed;
     private bool takeDamage = false;
     public Transform myTransform;
 
 
 
     // Use this for initialization
     void Start () {
         takeDamage = false;
         myTransform = transform;
         target = GameObject.FindWithTag("Player").transform;
         suspition = 0.0f;
     }
     
     // Update is called once per frame
     void Update () {
 
         if(takeDamage == true)
         {
             health -= 10;
         }
         if(health == 0)
         {
             gameObject.SetActive(false);
             takeDamage = false;
         }
           
         if(suspition == 100)
         {
             foundTarget = true;
         }
         else{
             foundTarget = false;
         }
         if(foundTarget && health > 0)
         {
             transform.LookAt(target);
             myTransform.Translate(Vector3.forward * movespeed * Time.deltaTime);
         }
 
 
     
     }
 
     void OnTriggerEnter(Collider other)
     {
         if(other.gameObject.tag == "Bullet")
         {
             takeDamage = true;
         }
 
         if(other.gameObject.tag == "Player")
         {
             foundTarget = true;
         }
     }
 
     void OnTriggerStay(Collider other)
     {
         if(other.gameObject.tag == "Bullet")
         {
             takeDamage = true;
         }
     }
 
     void OnTriggerExit(Collider other)
     {
         if(other.gameObject.tag == "Bullet")
         {
             takeDamage = false;
         }
     }
 }
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
1

Answer by getyour411 · Jan 13, 2014 at 12:04 AM

In the solder script, you set AI via GetCompent which would be the Soldier's AI. As I understand it, you want to access the AI on the Enemy. If that's the case, in your OnTrigger you would do something like

 if(other.gameObject.tag == "Enemy")
 AI enemyAI = other.gameObject.GetComponent<AI>();
 enemyAI.someVar = newValue;

You also might want to determine how you intend to spell Suspicion and be consistent about it.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What's wrong with my AI script. 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Damage the Player 1 Answer

; expected. Insert a semicolon at the end. 1 Answer

Script error help! 1 Answer


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