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 /
avatar image
0
Question by Adam Bruns · Feb 28, 2010 at 08:13 AM · errorsendmessagesyntax-errorjavascript-specific

Attack a Target (using mouse over?)

So in my script i have a "Monster" (a box) with a script that has the function:


var Player: Transform;

function OnMouseOver () { if (Input.GetMouseButtonDown(1)) { Player.SendMessage ("AttackMonster"); } }


I have the player set up as the character (obviously) and on that i have this script:


function AttackMonster()
{
print ("ATTACK");
}


now all this works just fine and dandy, no problems at all. But i want the "Monster" to send its location to the other script, so that way i can have the script move the player to the monsters location. I tried adding a var with the position:


var Player: Transform;
var targetPoint = transform.position;
function OnMouseOver () {
if (Input.GetMouseButtonDown(1)) {
Player.SendMessage ("AttackMonster",targetPoint,SendMessageOptions.DontRequireReceiver);
   }
}


I kept getting an Error saying that i cant call that function when declaring a variable, can i fix this? or do i have to do something completely different?

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

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Ashkan_gc · Feb 28, 2010 at 02:25 PM

what don't you use, GetComponent to get a reference to one of the scripts of the player and call it's functions.

player.GetComponent(attackscript).attack (position);

the SendMessage should work properly. the parameter than you send can be any type because it's an object.

Comment
Add comment · Show 2 · 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 Adam Bruns · Feb 28, 2010 at 06:37 PM 0
Share

thank you very much :) i got it working now

avatar image Ashkan_gc · Mar 01, 2010 at 05:05 AM 0
Share

nothing special. you should vote up answers that you think they are correct for other users. in this way they can know what answer is a better one. even when you mark something as best answer you should vote it up too.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

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

SendMessage StartSending has no receiver! 1 Answer

insert semicolon 2 Answers

Scripting Error! - UCE0001: ';' expected. Insert a semicolon at the end. 1 Answer

Cannot implicitly convert type `float' to `int'. An explicit conversion exists (are you missing a cast?) 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