Hi im working in my own game alone with no help, i have been watching tons of tutorials and reading more, but english is not my mother lenguage so i cant seem to repoduce or to fully understand whats going on... so for example if i want to create in unity a game object with is own gravity (Atract "projectile" but not the player) var gameObject= gravity; public var gameObjectGravity= 10 and if i want to "shoot" a game object that will be atracted to the gravity of that game object and when i press "E" botton the fuction of destroying will be set on or off. ( i took this code from another FPS as a basic to modify ) function start(){ if( Input.GetButtonDown( "e" ) ) var asExplosion : boolean = false; var explosion : GameObject; function (OnCollisionEnter collision : Collision ); var contact : ContactPoint = collision.contacts[0]; var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal ); var instantiatedExplosion : GameObject = Instantiate( explosion, contact.point, rotation ); Destroy( gameObject ); }
well... 1. none of that code does any gravity type pull? 2. you cant put functions inside functions (You have OnCollisionEnter inside Start, and its not even defined correctly anyway) 3. you should avoid using names that are similar/close to standard types/objects (ie gameObject, transform) I only code in c#, but ill give some js a go here... Code (csharp): var GravitySource : GameObject; var GravityPull : float = 10f; var GravityEnabled : bool = false; function Update() { GravityEnabled = !Input.GetKeyDown(KeyCode.E); if(GravityEnabled GravitySource != null) { transform.position = Vector3.MoveTowards(transform.position, GravitySource.position, GravityPull * Time.deltaTime); } } var explosion : GameObject; function OnCollisionEnter (collision : Collision ) { if(explosion != null) { var contact : ContactPoint = collision.contacts[0]; var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal ); var instantiatedExplosion : GameObject = Instantiate(explosion, contact.point, rotation ); } Destroy( gameObject ); }
thanks JamesLeeNZ your awesome for helping me out, now i cant try out the code because it says that this script is wrong or obsolete ???? something that haves going on with unity since update to 4.x... using UnityEngine; public class ActivateTrigger : MonoBehaviour { public enum Mode { Trigger = 0, // Just broadcast the action on to the target Replace = 1, // replace target with source Activate = 2, // Activate the target GameObject Enable = 3, // Enable a component Animate = 4, // Start animation on target Deactivate= 5 // Decativate target GameObject } /// The action to accomplish public Mode action = Mode.Activate; /// The game object to affect. If none, the trigger work on this game object public Object target; public GameObject source; public int triggerCount = 1;/// public bool repeatTrigger = false; void DoActivateTrigger () { triggerCount--; if (triggerCount == 0 || repeatTrigger) { Object currentTarget = target != null ? target : gameObject; Behaviour targetBehaviour = currentTarget as Behaviour; GameObject targetGameObject = currentTarget as GameObject; if (targetBehaviour != null) targetGameObject = targetBehaviour.gameObject; switch (action) { case Mode.Trigger: targetGameObject.BroadcastMessage ("DoActivateTrigger"); break; case Mode.Replace: if (source != null) { Object.Instantiate (source, targetGameObject.transform.position, targetGameObject.transform.rotation); DestroyObject (targetGameObject); } break; case Mode.Activate: GameObject = true; break; case Mode.Enable: if (targetBehaviour != null) targetBehaviour.enabled = true; break; case Mode.Animate: GameObject.animation.Play (); break; case Mode.Deactivate: GameObject.active = false; break; } } } void OnTriggerEnter (Collider other) { DoActivateTrigger (); } }
Just some general housekeeping to help us help you... In future, could you please wrap your code in the Code, or PHP tags? Also, when you are stating there is an error, please copy and paste the full error and identify which line of code it is applicable to? PHP: Function Start(){} Code (csharp): Function Start(){ } Judging by the sounds of your error, a function used by one or more of your lines of code is no longer supported or will be removed in an upcoming version of the Unity Editor.
probably this... GameObject.active = false; Think its been replaced with gameObject.SetActive(false); http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActive.html
im sorry guys for the inconvenience, ill try doing my best now on. Thanks again guys ur the best... all coding error fixed now lets try that code JamesLeeNZ help me out with.