Quantcast
Channel: Questions in topic: "exception"
Viewing all articles
Browse latest Browse all 470

,NullReferenceException Object reference not set to an instance of an object MechAttackMoveController.Awake () How do I fix this problem?

$
0
0
Hey there it's me Richard Haley once again just wanting to know how do I fix this problem it's NullReferenceException problem that say: NullReferenceException Object reference not set to an instance of an object MechAttackMoveController.Awake () (at Assets/Scripts/AI/MechAttackMoveController.js:31) here is the script that I have some one please please please do not ignore this ok so here is the script: 1#pragma strict 2 3// Public member data 4public var motor : MovementMotor; 5public var head : Transform; 6 7public var targetDistanceMin : float = 3.0; 8public var targetDistanceMax : float = 4.0; 9 10public var weaponBehaviours : MonoBehaviour[]; 11public var fireFrequency : float = 2; 12 13// Private memeber data 14private var ai : AI; 15 16private var character : Transform; 17 18private var player : Transform; 19 20private var inRange : boolean = false; 21private var nextRaycastTime : float = 0; 22private var lastRaycastSuccessfulTime : float = 0; 23private var noticeTime : float = 0; 24 25private var firing : boolean = false; 26private var lastFireTime : float = -1; 27private var nextWeaponToFire : int = 0; 28 29function Awake () { 30 character = motor.transform; 31 player = GameObject.FindWithTag ("Player").transform; 32 ai = transform.parent.GetComponentInChildren. (); 33} 34 35function OnEnable () { 36 inRange = false; 37 nextRaycastTime = Time.time + 1; 38 lastRaycastSuccessfulTime = Time.time; 39 noticeTime = Time.time; 40} 41 42function OnDisable () { 43 Shoot (false); 44} 45 46function Shoot (state : boolean) { 47 firing = state; 48} 49 50function Fire () { 51 if (weaponBehaviours[nextWeaponToFire]) { 52 weaponBehaviours[nextWeaponToFire].SendMessage ("Fire"); 53 nextWeaponToFire = (nextWeaponToFire + 1) % weaponBehaviours.Length; 54 lastFireTime = Time.time; 55 } 56} 57 58function Update () { 59 // Calculate the direction from the player to this character 60 var playerDirection : Vector3 = (player.position - character.position); 61 playerDirection.y = 0; 62 var playerDist : float = playerDirection.magnitude; 63 playerDirection /= playerDist; 64 65 // Set this character to face the player, 66 // that is, to face the direction from this character to the player 67 motor.facingDirection = playerDirection; 68 69 // For a short moment after noticing player, 70 // only look at him but don't walk towards or attack yet. 71 if (Time.time < noticeTime + 1.5) { 72 motor.movementDirection = Vector3.zero; 73 return; 74 } 75 76 if (inRange && playerDist > targetDistanceMax) 77 inRange = false; 78 if (!inRange && playerDist < targetDistanceMin) 79 inRange = true; 80 81 if (inRange) 82 motor.movementDirection = Vector3.zero; 83 else 84 motor.movementDirection = playerDirection; 85 86 if (Time.time > nextRaycastTime) { 87 nextRaycastTime = Time.time + 1; 88 if (ai.CanSeePlayer ()) { 89 lastRaycastSuccessfulTime = Time.time; 90 if (IsAimingAtPlayer ()) 91 Shoot (true); 92 else 93 Shoot (false); 94 } 95 else { 96 Shoot (false); 97 if (Time.time > lastRaycastSuccessfulTime + 5) { 98 ai.OnLostTrack (); 99 } 100 } 101 } 102 103 if (firing) { 104 if (Time.time > lastFireTime + 1 / fireFrequency) { 105 Fire (); 106 } 107 } 108} 109 110function IsAimingAtPlayer () : boolean { 111 var playerDirection : Vector3 = (player.position - head.position); 112 playerDirection.y = 0; 113 return Vector3.Angle (head.forward, playerDirection) < 15; 114} You can leave me a message at www.rb.haley@hotmail.com.

Viewing all articles
Browse latest Browse all 470

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>