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 /
avatar image
0
Question by Zane · Feb 12, 2011 at 07:38 AM · fps

Script Problems

How Can I make This code functional

var player : GameObject; var explosionRadius = 1; var explosionPower = 1; var explosionDamage = 100.0; var damage = 10; var enemyDamage : float=10f;

var explosionTime = 1.0;

function Start () {

 var explosionPosition = transform.position;
 var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, explosionRadius);

 for (var hit in colliders) {
     if (!hit)
         continue;

     if (hit.rigidbody) {
         hit.rigidbody.AddExplosionForce(explosionPower, explosionPosition, explosionRadius, 3.0);

         var closestPoint = hit.rigidbody.ClosestPointOnBounds(explosionPosition);
         var distance = Vector3.Distance(closestPoint, explosionPosition);

         // The hit points we apply fall decrease with distance from the hit point
         var hitPoints = 1.0 - Mathf.Clamp01(distance / explosionRadius);
         hitPoints *= explosionDamage;

         // Tell the rigidbody or any other script attached to the hit object 
         // how much damage is to be applied!
                 // I modified This part of the code. 
         hit.gameObject.player.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);
         hit.rigidbody.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);

     }


 }

 // stop emitting ?
 if (particleEmitter) {
     particleEmitter.emit = true;
     yield WaitForSeconds(0.5);
     particleEmitter.emit = false;
 }

 // destroy the explosion
 Destroy (gameObject, explosionTime);

}

I get the error "Player is not a member of unity game object" Thanks In Advance!

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
0

Answer by DaveA · Feb 12, 2011 at 08:30 AM

Where you have

hit.gameObject.player

get rid of .player

Comment
Add comment · Show 1 · 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 Zane · Feb 13, 2011 at 02:12 AM 0
Share

but I want it to be able to do damage to the player without having a rigid body attached to the player, how would I do this?

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

CS0116 "A namespace can only contain type and namespace declarations" 1 Answer

Problem with First Person Shooter Script 1 Answer

Weapon Possition Move On Sprint 1 Answer

How to make an enemy change tags after death. 3 Answers

Camera Recoil,Please help me. 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