问题在于该行始终为假:
#ifndef STATUS_H_INCLUDED
#define STATUS_H_INCLUDED
enum status {FALSE, TRUE};
typedef enum status Status;
#endif
#ifndef LINKED_LIST_H_INCLUDED
#define LINKED_LIST_H_INCLUDED
//include "status.h"
#include <stdio.h>
struct node
{
int data;
struct node *next;
};
typedef struct node Node;
Node* list_insert( Node *head, int data );
void print_list( Node *head );
void linked_list_destroy( Node** head );
void delete_node( Node** head, int data );
Status in_list( Node* head, int data );
void bytes_of_list( Node* head );
#endif
#include <stdio.h>
#include <stdlib.h>
//#include "linked_list.h"
int main( void )
{
int num = 0;
Node *head = NULL;
num = 7;
head = list_insert( head, num );
bytes_of_list( head );
head = list_insert( head, 9 );
bytes_of_list( head );
head = list_insert( head, 2 );
bytes_of_list( head );
head = list_insert( head, 8 );
bytes_of_list( head );
delete_node( &head, 6 );
delete_node( &head, 9 );
bytes_of_list( head );
print_list( head );
printf( "\n" );
linked_list_destroy( &head );
bytes_of_list( head );
return 0;
}
//#include <stdlib.h>
//#include <stdio.h>
//#include "linked_list.h"
//#include "status.h"
/************************************************************** list insert */
Node *list_insert( Node *head, int data )
{
printf( "\nInsert %d into list.\n", data );
Node *pNode = malloc( sizeof( Node ));
if( !pNode )
{
perror( "malloc failed" );
exit( 1 );
}
pNode->data = data;
pNode->next = head;
return pNode;
}
/****************************************************** linked_list_destroy */
void linked_list_destroy( Node** head )
{
Node* phead = *head;
Node* prevNode = NULL;
printf( "\nDestroy List:\n");
while( phead )
{
prevNode = phead;
phead = phead->next;
printf( "Deleting %d\n", prevNode->data );
prevNode->data = 0;
prevNode->next = NULL;
free( prevNode );
}
*head = NULL;
}
/*************************************************************** print_list */
void print_list( Node *head )
{
Node* pHead = head;
printf( "\nPrint list:\n");
while( pHead )
{
printf( "%d ", pHead->data );
pHead = pHead->next;
}
}
/*********************************************************** delete nodes */
void delete_node( Node **head, int data )
{
Node* phead = *head;
Node* prev = NULL;
printf( "\nDelete %d from list:\n", data );
//if( !head ) return;
while(( phead ) && ( phead->data != data ))
{
prev = phead;
phead = phead->next;
}
if( !phead )
{
printf( "Sorry, %d is not in the list.\n", data);
}
else
{
prev->next = phead->next;
free( phead );
}
return;
}
/********************************************************* bytes of list */
void bytes_of_list( Node* head )
{
Node* phead = head;
size_t bytes_total = 0;
while( phead )
{
bytes_total += sizeof( *phead );
phead = phead->next;
}
printf( "The current size of the list is %lu bytes.\n", bytes_total );
//return bytes_total;
}
我希望当我单击private void OnMouseOver()
{
if(Input.GetMouseButtonDown(0))
{
line.enabled = !line;
if (line.enabled == true)
CreatePoints();
}
}
时,将启用该行,然后单击GameObject
,然后再次单击,该行将为false,并且不会创建点。
更新:
添加了一个计数器,因此运行游戏时的默认状态为true,然后将其切换为false / true。
CreatePoints()
这很好用,但是使用这样的计数器是个好方法吗?
答案 0 :(得分:2)
if (Input.GetMouseButtonDown(0))
{
line.enabled = !line.enabled;
if (line.enabled)
CreatePoints();
}
您不能直接访问游戏对象的启用/禁用状态。您需要使用 .enabled 检索它,并将其相反的位置设置为打开和关闭。