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 /
  • Help Room /
avatar image
0
Question by PatrikAH · May 04, 2016 at 12:44 PM · javascript3dweapon

How to Equip/ Dequip by deleting a Gameobject

Hi, so I've been having some problems with making a script that allows the player to equip/ dequip a torch. My enemy AI is set to see if the torch is close to them, then they will attack. I've tried hiding it, but it doesn't destroy it so the enemy can still detect it. Im using Unity 3D and I'm running on Mac OSX. I also need the object to also be a child of my player.

Equip Script: #pragma strict

var projectile : GameObject; var fireRate : float = 0.5; internal var nextFire : float; var speed : float = 5; var weaponFireFX : AudioClip; var FirstPersonCharacter : Transform; var Torch : Transform;

function OnCollisionEnter (collision : Collision){ var Torch : Transform; FirstPersonCharacter = Instantiate(FirstPersonCharacter, Vector3.zero, Quaternion.identity); FirstPersonCharacter.parent = Torch; FirstPersonCharacter.localRotation = Quaternion.identity; // rotates the object like the parent FirstPersonCharacter.localPosition = Vector3(0.4790001,-0.9,0.32); // define here your "exact point" within the parent } function Start () {

}

function Update () {

 //fire1 button is left mouse or left control key
 

if (Input.GetButtonDown("space")) { GetComponent.().enabled = !GetComponent.().enabled; } if(Input.GetButtonDown("space")){ GetComponent.().enabled = !GetComponent.().enabled; } }

Enemy AI Script: var player : GameObject; var speed = 6.0; var range = 10.0; var hitRange = 5.0; var enemyDamage = 10.0; var rotationSpeed = 5.0;

function Start () { player = GameObject.FindGameObjectWithTag("Player"); }

function FixedUpdate() { //move towards player var distance = Vector3.Distance( player.transform.position, transform.position); if (distance > range) { return; }

 else
 {  

 var delta = player.transform.position - transform.position;
 delta.Normalize();
 delta.y = 0;
 var moveSpeed = speed * Time.deltaTime;
 transform.position = transform.position + (delta * moveSpeed);
   
 delta.y = 0;
 transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(delta),
 rotationSpeed * Time.deltaTime);
 transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0);
   
 if (distance < hitRange)
 {
     player.SendMessageUpwards
 ("ApplyDamage", enemyDamage, SendMessageOptions.DontRequireReceiver);
     }
 }

}

Thanks for your time :)

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

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

C# - JS problem. 1 Answer

Error when trying to make script for main menu. 0 Answers

Jump Script not Working JavaScript 1 Answer

Destroy a spawning enemy prefab with an weapon prefab 0 Answers

Trying to make a first person RPG 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